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

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

Issue 9419033: Move creation of BrowserContext objects that live in content to content, instead of depending on th… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fix memory leaks in tests Created 8 years, 10 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/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
11 #include "base/test/thread_test_helper.h" 11 #include "base/test/thread_test_helper.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/testing_profile.h" 15 #include "chrome/test/base/testing_profile.h"
16 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/browser/in_process_webkit/indexed_db_context.h" 17 #include "content/browser/in_process_webkit/indexed_db_context.h"
18 #include "content/browser/in_process_webkit/webkit_context.h" 18 #include "content/browser/in_process_webkit/webkit_context.h"
19 #include "content/browser/tab_contents/tab_contents.h" 19 #include "content/browser/tab_contents/tab_contents.h"
20 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
21 #include "webkit/database/database_util.h" 21 #include "webkit/database/database_util.h"
22 #include "webkit/quota/mock_special_storage_policy.h" 22 #include "webkit/quota/mock_special_storage_policy.h"
23 #include "webkit/quota/quota_manager.h" 23 #include "webkit/quota/quota_manager.h"
24 #include "webkit/quota/special_storage_policy.h" 24 #include "webkit/quota/special_storage_policy.h"
25 25
26 using content::BrowserContext;
26 using content::BrowserThread; 27 using content::BrowserThread;
27 using quota::QuotaManager; 28 using quota::QuotaManager;
28 using webkit_database::DatabaseUtil; 29 using webkit_database::DatabaseUtil;
29 30
30 // This browser test is aimed towards exercising the IndexedDB bindings and 31 // This browser test is aimed towards exercising the IndexedDB bindings and
31 // the actual implementation that lives in the browser side (in_process_webkit). 32 // the actual implementation that lives in the browser side (in_process_webkit).
32 class IndexedDBBrowserTest : public InProcessBrowserTest { 33 class IndexedDBBrowserTest : public InProcessBrowserTest {
33 public: 34 public:
34 IndexedDBBrowserTest() { 35 IndexedDBBrowserTest() {
35 EnableDOMAutomation(); 36 EnableDOMAutomation();
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 147
147 // Test our assumptions about what is protected and what is not. 148 // Test our assumptions about what is protected and what is not.
148 const GURL kProtectedOrigin("chrome-extension://foo/"); 149 const GURL kProtectedOrigin("chrome-extension://foo/");
149 const GURL kUnprotectedOrigin("http://foo/"); 150 const GURL kUnprotectedOrigin("http://foo/");
150 quota::SpecialStoragePolicy* policy = profile.GetSpecialStoragePolicy(); 151 quota::SpecialStoragePolicy* policy = profile.GetSpecialStoragePolicy();
151 ASSERT_TRUE(policy->IsStorageProtected(kProtectedOrigin)); 152 ASSERT_TRUE(policy->IsStorageProtected(kProtectedOrigin));
152 ASSERT_FALSE(policy->IsStorageProtected(kUnprotectedOrigin)); 153 ASSERT_FALSE(policy->IsStorageProtected(kUnprotectedOrigin));
153 154
154 // Create some indexedDB paths. 155 // Create some indexedDB paths.
155 // With the levelDB backend, these are directories. 156 // With the levelDB backend, these are directories.
156 WebKitContext *webkit_context = profile.GetWebKitContext(); 157 WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile);
157 IndexedDBContext* idb_context = webkit_context->indexed_db_context(); 158 IndexedDBContext* idb_context = webkit_context->indexed_db_context();
158 idb_context->set_data_path_for_testing(temp_dir.path()); 159 idb_context->set_data_path_for_testing(temp_dir.path());
159 protected_path = idb_context->GetIndexedDBFilePath( 160 protected_path = idb_context->GetIndexedDBFilePath(
160 DatabaseUtil::GetOriginIdentifier(kProtectedOrigin)); 161 DatabaseUtil::GetOriginIdentifier(kProtectedOrigin));
161 unprotected_path = idb_context->GetIndexedDBFilePath( 162 unprotected_path = idb_context->GetIndexedDBFilePath(
162 DatabaseUtil::GetOriginIdentifier(kUnprotectedOrigin)); 163 DatabaseUtil::GetOriginIdentifier(kUnprotectedOrigin));
163 ASSERT_TRUE(file_util::CreateDirectory(protected_path)); 164 ASSERT_TRUE(file_util::CreateDirectory(protected_path));
164 ASSERT_TRUE(file_util::CreateDirectory(unprotected_path)); 165 ASSERT_TRUE(file_util::CreateDirectory(unprotected_path));
165 166
166 // Setup to clear all unprotected origins on exit. 167 // Setup to clear all unprotected origins on exit.
167 webkit_context->set_clear_local_state_on_exit(true); 168 webkit_context->set_clear_local_state_on_exit(true);
168 } 169 }
169 170
170 // Make sure we wait until the destructor has run. 171 // Make sure we wait until the destructor has run.
171 scoped_refptr<base::ThreadTestHelper> helper( 172 scoped_refptr<base::ThreadTestHelper> helper_io(
173 new base::ThreadTestHelper(
174 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
175 ASSERT_TRUE(helper_io->Run());
176 scoped_refptr<base::ThreadTestHelper> helper_webkit(
172 new base::ThreadTestHelper( 177 new base::ThreadTestHelper(
173 BrowserThread::GetMessageLoopProxyForThread( 178 BrowserThread::GetMessageLoopProxyForThread(
174 BrowserThread::WEBKIT_DEPRECATED))); 179 BrowserThread::WEBKIT_DEPRECATED)));
175 ASSERT_TRUE(helper->Run()); 180 ASSERT_TRUE(helper_webkit->Run());
176 181
177 ASSERT_TRUE(file_util::DirectoryExists(protected_path)); 182 ASSERT_TRUE(file_util::DirectoryExists(protected_path));
178 ASSERT_FALSE(file_util::DirectoryExists(unprotected_path)); 183 ASSERT_FALSE(file_util::DirectoryExists(unprotected_path));
179 } 184 }
180 185
181 // In proc browser test is needed here because ClearLocalState indirectly calls 186 // In proc browser test is needed here because ClearLocalState indirectly calls
182 // WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin. 187 // WebKit's isMainThread through WebSecurityOrigin->SecurityOrigin.
183 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearSessionOnlyDatabases) { 188 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ClearSessionOnlyDatabases) {
184 ScopedTempDir temp_dir; 189 ScopedTempDir temp_dir;
185 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 190 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
186 191
187 FilePath normal_path; 192 FilePath normal_path;
188 FilePath session_only_path; 193 FilePath session_only_path;
189 194
190 // Create the scope which will ensure we run the destructor of the webkit 195 // Create the scope which will ensure we run the destructor of the webkit
191 // context which should trigger the clean up. 196 // context which should trigger the clean up.
192 { 197 {
193 TestingProfile profile; 198 TestingProfile profile;
194 199
195 const GURL kNormalOrigin("http://normal/"); 200 const GURL kNormalOrigin("http://normal/");
196 const GURL kSessionOnlyOrigin("http://session-only/"); 201 const GURL kSessionOnlyOrigin("http://session-only/");
197 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = 202 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
198 new quota::MockSpecialStoragePolicy; 203 new quota::MockSpecialStoragePolicy;
199 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); 204 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin);
200 205
201 // Create some indexedDB paths. 206 // Create some indexedDB paths.
202 // With the levelDB backend, these are directories. 207 // With the levelDB backend, these are directories.
203 WebKitContext *webkit_context = profile.GetWebKitContext(); 208 WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile);
204 IndexedDBContext* idb_context = webkit_context->indexed_db_context(); 209 IndexedDBContext* idb_context = webkit_context->indexed_db_context();
205 210
206 // Override the storage policy with our own. 211 // Override the storage policy with our own.
207 idb_context->special_storage_policy_ = special_storage_policy; 212 idb_context->special_storage_policy_ = special_storage_policy;
208 idb_context->set_data_path_for_testing(temp_dir.path()); 213 idb_context->set_data_path_for_testing(temp_dir.path());
209 214
210 normal_path = idb_context->GetIndexedDBFilePath( 215 normal_path = idb_context->GetIndexedDBFilePath(
211 DatabaseUtil::GetOriginIdentifier(kNormalOrigin)); 216 DatabaseUtil::GetOriginIdentifier(kNormalOrigin));
212 session_only_path = idb_context->GetIndexedDBFilePath( 217 session_only_path = idb_context->GetIndexedDBFilePath(
213 DatabaseUtil::GetOriginIdentifier(kSessionOnlyOrigin)); 218 DatabaseUtil::GetOriginIdentifier(kSessionOnlyOrigin));
214 ASSERT_TRUE(file_util::CreateDirectory(normal_path)); 219 ASSERT_TRUE(file_util::CreateDirectory(normal_path));
215 ASSERT_TRUE(file_util::CreateDirectory(session_only_path)); 220 ASSERT_TRUE(file_util::CreateDirectory(session_only_path));
216 } 221 }
217 222
218 // Make sure we wait until the destructor has run. 223 scoped_refptr<base::ThreadTestHelper> helper_io(
219 scoped_refptr<base::ThreadTestHelper> helper( 224 new base::ThreadTestHelper(
225 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
226 ASSERT_TRUE(helper_io->Run());
227 scoped_refptr<base::ThreadTestHelper> helper_webkit(
220 new base::ThreadTestHelper( 228 new base::ThreadTestHelper(
221 BrowserThread::GetMessageLoopProxyForThread( 229 BrowserThread::GetMessageLoopProxyForThread(
222 BrowserThread::WEBKIT_DEPRECATED))); 230 BrowserThread::WEBKIT_DEPRECATED)));
223 ASSERT_TRUE(helper->Run()); 231 ASSERT_TRUE(helper_webkit->Run());
224 232
225 EXPECT_TRUE(file_util::DirectoryExists(normal_path)); 233 EXPECT_TRUE(file_util::DirectoryExists(normal_path));
226 EXPECT_FALSE(file_util::DirectoryExists(session_only_path)); 234 EXPECT_FALSE(file_util::DirectoryExists(session_only_path));
227 } 235 }
228 236
229 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, SaveSessionState) { 237 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, SaveSessionState) {
230 ScopedTempDir temp_dir; 238 ScopedTempDir temp_dir;
231 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 239 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
232 240
233 FilePath normal_path; 241 FilePath normal_path;
234 FilePath session_only_path; 242 FilePath session_only_path;
235 243
236 // Create the scope which will ensure we run the destructor of the webkit 244 // Create the scope which will ensure we run the destructor of the webkit
237 // context. 245 // context.
238 { 246 {
239 TestingProfile profile; 247 TestingProfile profile;
240 248
241 const GURL kNormalOrigin("http://normal/"); 249 const GURL kNormalOrigin("http://normal/");
242 const GURL kSessionOnlyOrigin("http://session-only/"); 250 const GURL kSessionOnlyOrigin("http://session-only/");
243 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = 251 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
244 new quota::MockSpecialStoragePolicy; 252 new quota::MockSpecialStoragePolicy;
245 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin); 253 special_storage_policy->AddSessionOnly(kSessionOnlyOrigin);
246 254
247 // Create some indexedDB paths. 255 // Create some indexedDB paths.
248 // With the levelDB backend, these are directories. 256 // With the levelDB backend, these are directories.
249 WebKitContext *webkit_context = profile.GetWebKitContext(); 257 WebKitContext* webkit_context = BrowserContext::GetWebKitContext(&profile);
250 IndexedDBContext* idb_context = webkit_context->indexed_db_context(); 258 IndexedDBContext* idb_context = webkit_context->indexed_db_context();
251 259
252 // Override the storage policy with our own. 260 // Override the storage policy with our own.
253 idb_context->special_storage_policy_ = special_storage_policy; 261 idb_context->special_storage_policy_ = special_storage_policy;
254 idb_context->set_clear_local_state_on_exit(true); 262 idb_context->set_clear_local_state_on_exit(true);
255 idb_context->set_data_path_for_testing(temp_dir.path()); 263 idb_context->set_data_path_for_testing(temp_dir.path());
256 264
257 // Save session state. This should bypass the destruction-time deletion. 265 // Save session state. This should bypass the destruction-time deletion.
258 idb_context->SaveSessionState(); 266 idb_context->SaveSessionState();
259 267
(...skipping 17 matching lines...) Expand all
277 EXPECT_TRUE(file_util::DirectoryExists(session_only_path)); 285 EXPECT_TRUE(file_util::DirectoryExists(session_only_path));
278 } 286 }
279 287
280 class IndexedDBBrowserTestWithLowQuota : public IndexedDBBrowserTest { 288 class IndexedDBBrowserTestWithLowQuota : public IndexedDBBrowserTest {
281 public: 289 public:
282 virtual void SetUpOnMainThread() { 290 virtual void SetUpOnMainThread() {
283 const int kInitialQuotaKilobytes = 5000; 291 const int kInitialQuotaKilobytes = 5000;
284 const int kTemporaryStorageQuotaMaxSize = kInitialQuotaKilobytes 292 const int kTemporaryStorageQuotaMaxSize = kInitialQuotaKilobytes
285 * 1024 * QuotaManager::kPerHostTemporaryPortion; 293 * 1024 * QuotaManager::kPerHostTemporaryPortion;
286 SetTempQuota( 294 SetTempQuota(
287 kTemporaryStorageQuotaMaxSize, browser()->profile()->GetQuotaManager()); 295 kTemporaryStorageQuotaMaxSize,
296 content::BrowserContext::GetQuotaManager(browser()->profile()));
288 } 297 }
289 298
290 static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) { 299 static void SetTempQuota(int64 bytes, scoped_refptr<QuotaManager> qm) {
291 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 300 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
292 BrowserThread::PostTask( 301 BrowserThread::PostTask(
293 BrowserThread::IO, FROM_HERE, 302 BrowserThread::IO, FROM_HERE,
294 base::Bind(&IndexedDBBrowserTestWithLowQuota::SetTempQuota, bytes, 303 base::Bind(&IndexedDBBrowserTestWithLowQuota::SetTempQuota, bytes,
295 qm)); 304 qm));
296 return; 305 return;
297 } 306 }
(...skipping 18 matching lines...) Expand all
316 virtual void SetUpCommandLine(CommandLine* command_line) { 325 virtual void SetUpCommandLine(CommandLine* command_line) {
317 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); 326 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
318 } 327 }
319 }; 328 };
320 329
321 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed, 330 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed,
322 DatabaseCallbacksTest) { 331 DatabaseCallbacksTest) {
323 SimpleTest( 332 SimpleTest(
324 testUrl(FilePath(FILE_PATH_LITERAL("database_callbacks_first.html")))); 333 testUrl(FilePath(FILE_PATH_LITERAL("database_callbacks_first.html"))));
325 } 334 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698