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

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

Issue 18660012: IndexedDB: Test for "close" event when connection is force-closed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More context simplification Created 7 years, 5 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
« no previous file with comments | « no previous file | content/test/data/indexeddb/force_close_event.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); 222 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc");
223 } 223 }
224 }; 224 };
225 225
226 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed, 226 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithGCExposed,
227 DatabaseCallbacksTest) { 227 DatabaseCallbacksTest) {
228 SimpleTest(GetTestUrl("indexeddb", "database_callbacks_first.html")); 228 SimpleTest(GetTestUrl("indexeddb", "database_callbacks_first.html"));
229 } 229 }
230 230
231 static void CopyLevelDBToProfile(Shell* shell, 231 static void CopyLevelDBToProfile(Shell* shell,
232 scoped_refptr<IndexedDBContext> context, 232 scoped_refptr<IndexedDBContextImpl> context,
233 const std::string& test_directory) { 233 const std::string& test_directory) {
234 DCHECK(context->TaskRunner()->RunsTasksOnCurrentThread()); 234 DCHECK(context->TaskRunner()->RunsTasksOnCurrentThread());
235 base::FilePath leveldb_dir(FILE_PATH_LITERAL("file__0.indexeddb.leveldb")); 235 base::FilePath leveldb_dir(FILE_PATH_LITERAL("file__0.indexeddb.leveldb"));
236 base::FilePath test_data_dir = 236 base::FilePath test_data_dir =
237 GetTestFilePath("indexeddb", test_directory.c_str()).Append(leveldb_dir); 237 GetTestFilePath("indexeddb", test_directory.c_str()).Append(leveldb_dir);
238 IndexedDBContextImpl* context_impl = 238 base::FilePath dest = context->data_path().Append(leveldb_dir);
jsbell 2013/07/11 00:17:09 Unrelated simplification.
239 static_cast<IndexedDBContextImpl*>(context.get());
240 base::FilePath dest = context_impl->data_path().Append(leveldb_dir);
241 // If we don't create the destination directory first, the contents of the 239 // If we don't create the destination directory first, the contents of the
242 // leveldb directory are copied directly into profile/IndexedDB instead of 240 // leveldb directory are copied directly into profile/IndexedDB instead of
243 // profile/IndexedDB/file__0.xxx/ 241 // profile/IndexedDB/file__0.xxx/
244 ASSERT_TRUE(file_util::CreateDirectory(dest)); 242 ASSERT_TRUE(file_util::CreateDirectory(dest));
245 const bool kRecursive = true; 243 const bool kRecursive = true;
246 ASSERT_TRUE(base::CopyDirectory(test_data_dir, 244 ASSERT_TRUE(base::CopyDirectory(test_data_dir,
247 context_impl->data_path(), 245 context->data_path(),
248 kRecursive)); 246 kRecursive));
249 } 247 }
250 248
251 class IndexedDBBrowserTestWithPreexistingLevelDB : public IndexedDBBrowserTest { 249 class IndexedDBBrowserTestWithPreexistingLevelDB : public IndexedDBBrowserTest {
252 public: 250 public:
253 virtual void SetUpOnMainThread() OVERRIDE { 251 virtual void SetUpOnMainThread() OVERRIDE {
254 scoped_refptr<IndexedDBContextImpl> context = GetContext(); 252 scoped_refptr<IndexedDBContextImpl> context = GetContext();
255 context->TaskRunner()->PostTask( 253 context->TaskRunner()->PostTask(
256 FROM_HERE, 254 FROM_HERE,
257 base::Bind( 255 base::Bind(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 int64 original_size = RequestDiskUsage(); 335 int64 original_size = RequestDiskUsage();
338 EXPECT_GT(original_size, 0); 336 EXPECT_GT(original_size, 0);
339 SimpleTest(GetTestUrl("indexeddb", "open_bad_db.html")); 337 SimpleTest(GetTestUrl("indexeddb", "open_bad_db.html"));
340 int64 new_size = RequestDiskUsage(); 338 int64 new_size = RequestDiskUsage();
341 EXPECT_NE(original_size, new_size); 339 EXPECT_NE(original_size, new_size);
342 } 340 }
343 341
344 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, LevelDBLogFileTest) { 342 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, LevelDBLogFileTest) {
345 // Any page that opens an IndexedDB will work here. 343 // Any page that opens an IndexedDB will work here.
346 SimpleTest(GetTestUrl("indexeddb", "database_test.html")); 344 SimpleTest(GetTestUrl("indexeddb", "database_test.html"));
347 scoped_refptr<IndexedDBContext> context =
jsbell 2013/07/11 00:17:09 Unrelated simplification.
348 BrowserContext::GetDefaultStoragePartition(
349 shell()->web_contents()->GetBrowserContext())->
350 GetIndexedDBContext();
351 IndexedDBContextImpl* context_impl =
352 static_cast<IndexedDBContextImpl*>(context.get());
353 base::FilePath leveldb_dir(FILE_PATH_LITERAL("file__0.indexeddb.leveldb")); 345 base::FilePath leveldb_dir(FILE_PATH_LITERAL("file__0.indexeddb.leveldb"));
354 base::FilePath log_file(FILE_PATH_LITERAL("LOG")); 346 base::FilePath log_file(FILE_PATH_LITERAL("LOG"));
355 base::FilePath log_file_path = 347 base::FilePath log_file_path =
356 context_impl->data_path().Append(leveldb_dir).Append(log_file); 348 GetContext()->data_path().Append(leveldb_dir).Append(log_file);
357 int64 size; 349 int64 size;
358 EXPECT_TRUE(file_util::GetFileSize(log_file_path, &size)); 350 EXPECT_TRUE(file_util::GetFileSize(log_file_path, &size));
359 EXPECT_GT(size, 0); 351 EXPECT_GT(size, 0);
360 } 352 }
361 353
362 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CanDeleteWhenOverQuotaTest) { 354 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CanDeleteWhenOverQuotaTest) {
363 SimpleTest(GetTestUrl("indexeddb", "fill_up_5k.html")); 355 SimpleTest(GetTestUrl("indexeddb", "fill_up_5k.html"));
364 int64 size = RequestDiskUsage(); 356 int64 size = RequestDiskUsage();
365 const int kQuotaKilobytes = 2; 357 const int kQuotaKilobytes = 2;
366 EXPECT_GT(size, kQuotaKilobytes * 1024); 358 EXPECT_GT(size, kQuotaKilobytes * 1024);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 string16 expected_title16(ASCIIToUTF16("setVersion(3) complete")); 407 string16 expected_title16(ASCIIToUTF16("setVersion(3) complete"));
416 TitleWatcher title_watcher(new_shell->web_contents(), expected_title16); 408 TitleWatcher title_watcher(new_shell->web_contents(), expected_title16);
417 409
418 base::KillProcess( 410 base::KillProcess(
419 shell()->web_contents()->GetRenderProcessHost()->GetHandle(), 0, true); 411 shell()->web_contents()->GetRenderProcessHost()->GetHandle(), 0, true);
420 shell()->Close(); 412 shell()->Close();
421 413
422 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); 414 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
423 } 415 }
424 416
417 // Verify that a "close" event is fired at database connections when
418 // the backing store is deleted.
419 IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ForceCloseEventTest) {
420 NavigateAndWaitForTitle(shell(), "force_close_event.html", NULL,
421 "connection ready");
422
423 GetContext()->TaskRunner()->PostTask(
424 FROM_HERE,
425 base::Bind(&IndexedDBContextImpl::DeleteForOrigin,
426 GetContext(),
427 GURL("file:///")));
428
429 string16 expected_title16(ASCIIToUTF16("connection closed"));
430 TitleWatcher title_watcher(shell()->web_contents(), expected_title16);
431 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
432 }
433
425 } // namespace content 434 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/test/data/indexeddb/force_close_event.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698