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

Side by Side Diff: webkit/browser/database/database_tracker_unittest.cc

Issue 100573002: Move directory creation functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | « webkit/browser/database/database_tracker.cc ('k') | webkit/browser/database/vfs_backend.cc » ('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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 const base::string16 kDB3 = ASCIIToUTF16("db3"); 222 const base::string16 kDB3 = ASCIIToUTF16("db3");
223 const base::string16 kDescription = ASCIIToUTF16("database_description"); 223 const base::string16 kDescription = ASCIIToUTF16("database_description");
224 224
225 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, 225 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
226 &database_size); 226 &database_size);
227 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0, 227 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
228 &database_size); 228 &database_size);
229 tracker->DatabaseOpened(kOrigin2, kDB3, kDescription, 0, 229 tracker->DatabaseOpened(kOrigin2, kDB3, kDescription, 0,
230 &database_size); 230 &database_size);
231 231
232 EXPECT_TRUE(file_util::CreateDirectory( 232 EXPECT_TRUE(base::CreateDirectory(
233 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( 233 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe(
234 tracker->GetOriginDirectory(kOrigin1))))); 234 tracker->GetOriginDirectory(kOrigin1)))));
235 EXPECT_TRUE(file_util::CreateDirectory( 235 EXPECT_TRUE(base::CreateDirectory(
236 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( 236 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe(
237 tracker->GetOriginDirectory(kOrigin2))))); 237 tracker->GetOriginDirectory(kOrigin2)))));
238 EXPECT_EQ(1, file_util::WriteFile( 238 EXPECT_EQ(1, file_util::WriteFile(
239 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1)); 239 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1));
240 EXPECT_EQ(2, file_util::WriteFile( 240 EXPECT_EQ(2, file_util::WriteFile(
241 tracker->GetFullDBFilePath(kOrigin2, kDB2), "aa", 2)); 241 tracker->GetFullDBFilePath(kOrigin2, kDB2), "aa", 2));
242 EXPECT_EQ(3, file_util::WriteFile( 242 EXPECT_EQ(3, file_util::WriteFile(
243 tracker->GetFullDBFilePath(kOrigin2, kDB3), "aaa", 3)); 243 tracker->GetFullDBFilePath(kOrigin2, kDB3), "aaa", 3));
244 tracker->DatabaseModified(kOrigin1, kDB1); 244 tracker->DatabaseModified(kOrigin1, kDB1);
245 tracker->DatabaseModified(kOrigin2, kDB2); 245 tracker->DatabaseModified(kOrigin2, kDB2);
(...skipping 11 matching lines...) Expand all
257 EXPECT_EQ(kDB1, observer.GetNotificationDatabaseName()); 257 EXPECT_EQ(kDB1, observer.GetNotificationDatabaseName());
258 tracker->DatabaseClosed(kOrigin1, kDB1); 258 tracker->DatabaseClosed(kOrigin1, kDB1);
259 result = callback.GetResult(result); 259 result = callback.GetResult(result);
260 EXPECT_EQ(net::OK, result); 260 EXPECT_EQ(net::OK, result);
261 EXPECT_FALSE(base::PathExists( 261 EXPECT_FALSE(base::PathExists(
262 tracker->DatabaseDirectory().AppendASCII(kOrigin1))); 262 tracker->DatabaseDirectory().AppendASCII(kOrigin1)));
263 263
264 // Recreate db1. 264 // Recreate db1.
265 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, 265 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
266 &database_size); 266 &database_size);
267 EXPECT_TRUE(file_util::CreateDirectory( 267 EXPECT_TRUE(base::CreateDirectory(
268 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( 268 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe(
269 tracker->GetOriginDirectory(kOrigin1))))); 269 tracker->GetOriginDirectory(kOrigin1)))));
270 EXPECT_EQ(1, file_util::WriteFile( 270 EXPECT_EQ(1, file_util::WriteFile(
271 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1)); 271 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1));
272 tracker->DatabaseModified(kOrigin1, kDB1); 272 tracker->DatabaseModified(kOrigin1, kDB1);
273 273
274 // Setup file modification times. db1 and db2 are modified now, db3 three 274 // Setup file modification times. db1 and db2 are modified now, db3 three
275 // days ago. 275 // days ago.
276 EXPECT_TRUE(file_util::SetLastModifiedTime( 276 EXPECT_TRUE(file_util::SetLastModifiedTime(
277 tracker->GetFullDBFilePath(kOrigin1, kDB1), base::Time::Now())); 277 tracker->GetFullDBFilePath(kOrigin1, kDB1), base::Time::Now()));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 EXPECT_EQ(0, database_size); 350 EXPECT_EQ(0, database_size);
351 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0, 351 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
352 &database_size); 352 &database_size);
353 EXPECT_EQ(0, database_size); 353 EXPECT_EQ(0, database_size);
354 tracker->DatabaseOpened(kOrigin1, kDB3, kDescription, 0, 354 tracker->DatabaseOpened(kOrigin1, kDB3, kDescription, 0,
355 &database_size); 355 &database_size);
356 EXPECT_EQ(0, database_size); 356 EXPECT_EQ(0, database_size);
357 357
358 // Write some data to each file and check that the listeners are 358 // Write some data to each file and check that the listeners are
359 // called with the appropriate values. 359 // called with the appropriate values.
360 EXPECT_TRUE(file_util::CreateDirectory( 360 EXPECT_TRUE(base::CreateDirectory(
361 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( 361 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe(
362 tracker->GetOriginDirectory(kOrigin1))))); 362 tracker->GetOriginDirectory(kOrigin1)))));
363 EXPECT_TRUE(file_util::CreateDirectory( 363 EXPECT_TRUE(base::CreateDirectory(
364 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( 364 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe(
365 tracker->GetOriginDirectory(kOrigin2))))); 365 tracker->GetOriginDirectory(kOrigin2)))));
366 EXPECT_EQ(1, file_util::WriteFile( 366 EXPECT_EQ(1, file_util::WriteFile(
367 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1)); 367 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1));
368 EXPECT_EQ(2, file_util::WriteFile( 368 EXPECT_EQ(2, file_util::WriteFile(
369 tracker->GetFullDBFilePath(kOrigin2, kDB2), "aa", 2)); 369 tracker->GetFullDBFilePath(kOrigin2, kDB2), "aa", 2));
370 EXPECT_EQ(4, file_util::WriteFile( 370 EXPECT_EQ(4, file_util::WriteFile(
371 tracker->GetFullDBFilePath(kOrigin1, kDB3), "aaaa", 4)); 371 tracker->GetFullDBFilePath(kOrigin1, kDB3), "aaaa", 4));
372 tracker->DatabaseModified(kOrigin1, kDB1); 372 tracker->DatabaseModified(kOrigin1, kDB1);
373 CheckNotificationReceived(&observer1, kOrigin1, kDB1, 1); 373 CheckNotificationReceived(&observer1, kOrigin1, kDB1, 1);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 // Create a database and modify it a couple of times, close it, 477 // Create a database and modify it a couple of times, close it,
478 // then delete it. Observe the tracker notifies accordingly. 478 // then delete it. Observe the tracker notifies accordingly.
479 479
480 int64 database_size = 0; 480 int64 database_size = 0;
481 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0, 481 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0,
482 &database_size); 482 &database_size);
483 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin)); 483 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin));
484 test_quota_proxy->reset(); 484 test_quota_proxy->reset();
485 485
486 base::FilePath db_file(tracker->GetFullDBFilePath(kOriginId, kName)); 486 base::FilePath db_file(tracker->GetFullDBFilePath(kOriginId, kName));
487 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); 487 EXPECT_TRUE(base::CreateDirectory(db_file.DirName()));
488 EXPECT_TRUE(EnsureFileOfSize(db_file, 10)); 488 EXPECT_TRUE(EnsureFileOfSize(db_file, 10));
489 tracker->DatabaseModified(kOriginId, kName); 489 tracker->DatabaseModified(kOriginId, kName);
490 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 10)); 490 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 10));
491 test_quota_proxy->reset(); 491 test_quota_proxy->reset();
492 492
493 EXPECT_TRUE(EnsureFileOfSize(db_file, 100)); 493 EXPECT_TRUE(EnsureFileOfSize(db_file, 100));
494 tracker->DatabaseModified(kOriginId, kName); 494 tracker->DatabaseModified(kOriginId, kName);
495 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 90)); 495 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 90));
496 test_quota_proxy->reset(); 496 test_quota_proxy->reset();
497 497
498 tracker->DatabaseClosed(kOriginId, kName); 498 tracker->DatabaseClosed(kOriginId, kName);
499 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin)); 499 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin));
500 EXPECT_EQ(net::OK, tracker->DeleteDatabase( 500 EXPECT_EQ(net::OK, tracker->DeleteDatabase(
501 kOriginId, kName, net::CompletionCallback())); 501 kOriginId, kName, net::CompletionCallback()));
502 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, -100)); 502 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, -100));
503 test_quota_proxy->reset(); 503 test_quota_proxy->reset();
504 504
505 // Create a database and modify it, try to delete it while open, 505 // Create a database and modify it, try to delete it while open,
506 // then close it (at which time deletion will actually occur). 506 // then close it (at which time deletion will actually occur).
507 // Observe the tracker notifies accordingly. 507 // Observe the tracker notifies accordingly.
508 508
509 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0, 509 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0,
510 &database_size); 510 &database_size);
511 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin)); 511 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin));
512 test_quota_proxy->reset(); 512 test_quota_proxy->reset();
513 513
514 db_file = tracker->GetFullDBFilePath(kOriginId, kName); 514 db_file = tracker->GetFullDBFilePath(kOriginId, kName);
515 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); 515 EXPECT_TRUE(base::CreateDirectory(db_file.DirName()));
516 EXPECT_TRUE(EnsureFileOfSize(db_file, 100)); 516 EXPECT_TRUE(EnsureFileOfSize(db_file, 100));
517 tracker->DatabaseModified(kOriginId, kName); 517 tracker->DatabaseModified(kOriginId, kName);
518 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 100)); 518 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 100));
519 test_quota_proxy->reset(); 519 test_quota_proxy->reset();
520 520
521 EXPECT_EQ(net::ERR_IO_PENDING, 521 EXPECT_EQ(net::ERR_IO_PENDING,
522 tracker->DeleteDatabase(kOriginId, kName, 522 tracker->DeleteDatabase(kOriginId, kName,
523 net::CompletionCallback())); 523 net::CompletionCallback()));
524 EXPECT_FALSE(test_quota_proxy->WasModificationNotified(kOrigin, -100)); 524 EXPECT_FALSE(test_quota_proxy->WasModificationNotified(kOrigin, -100));
525 525
526 tracker->DatabaseClosed(kOriginId, kName); 526 tracker->DatabaseClosed(kOriginId, kName);
527 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin)); 527 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin));
528 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, -100)); 528 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, -100));
529 test_quota_proxy->reset(); 529 test_quota_proxy->reset();
530 530
531 // Create a database and up the file size without telling 531 // Create a database and up the file size without telling
532 // the tracker about the modification, than simulate a 532 // the tracker about the modification, than simulate a
533 // a renderer crash. 533 // a renderer crash.
534 // Observe the tracker notifies accordingly. 534 // Observe the tracker notifies accordingly.
535 535
536 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0, 536 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0,
537 &database_size); 537 &database_size);
538 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin)); 538 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin));
539 test_quota_proxy->reset(); 539 test_quota_proxy->reset();
540 db_file = tracker->GetFullDBFilePath(kOriginId, kName); 540 db_file = tracker->GetFullDBFilePath(kOriginId, kName);
541 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); 541 EXPECT_TRUE(base::CreateDirectory(db_file.DirName()));
542 EXPECT_TRUE(EnsureFileOfSize(db_file, 100)); 542 EXPECT_TRUE(EnsureFileOfSize(db_file, 100));
543 DatabaseConnections crashed_renderer_connections; 543 DatabaseConnections crashed_renderer_connections;
544 crashed_renderer_connections.AddConnection(kOriginId, kName); 544 crashed_renderer_connections.AddConnection(kOriginId, kName);
545 EXPECT_FALSE(test_quota_proxy->WasModificationNotified(kOrigin, 100)); 545 EXPECT_FALSE(test_quota_proxy->WasModificationNotified(kOrigin, 100));
546 tracker->CloseDatabases(crashed_renderer_connections); 546 tracker->CloseDatabases(crashed_renderer_connections);
547 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 100)); 547 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 100));
548 548
549 // Cleanup. 549 // Cleanup.
550 crashed_renderer_connections.RemoveAllConnections(); 550 crashed_renderer_connections.RemoveAllConnections();
551 test_quota_proxy->SimulateQuotaManagerDestroyed(); 551 test_quota_proxy->SimulateQuotaManagerDestroyed();
(...skipping 30 matching lines...) Expand all
582 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, 582 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
583 &database_size); 583 &database_size);
584 EXPECT_EQ(0, database_size); 584 EXPECT_EQ(0, database_size);
585 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0, 585 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
586 &database_size); 586 &database_size);
587 EXPECT_EQ(0, database_size); 587 EXPECT_EQ(0, database_size);
588 588
589 // Write some data to each file. 589 // Write some data to each file.
590 base::FilePath db_file; 590 base::FilePath db_file;
591 db_file = tracker->GetFullDBFilePath(kOrigin1, kDB1); 591 db_file = tracker->GetFullDBFilePath(kOrigin1, kDB1);
592 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); 592 EXPECT_TRUE(base::CreateDirectory(db_file.DirName()));
593 EXPECT_TRUE(EnsureFileOfSize(db_file, 1)); 593 EXPECT_TRUE(EnsureFileOfSize(db_file, 1));
594 594
595 db_file = tracker->GetFullDBFilePath(kOrigin2, kDB2); 595 db_file = tracker->GetFullDBFilePath(kOrigin2, kDB2);
596 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); 596 EXPECT_TRUE(base::CreateDirectory(db_file.DirName()));
597 EXPECT_TRUE(EnsureFileOfSize(db_file, 2)); 597 EXPECT_TRUE(EnsureFileOfSize(db_file, 2));
598 598
599 // Store the origin database directories as long as they still exist. 599 // Store the origin database directories as long as they still exist.
600 origin1_db_dir = tracker->GetFullDBFilePath(kOrigin1, kDB1).DirName(); 600 origin1_db_dir = tracker->GetFullDBFilePath(kOrigin1, kDB1).DirName();
601 origin2_db_dir = tracker->GetFullDBFilePath(kOrigin2, kDB2).DirName(); 601 origin2_db_dir = tracker->GetFullDBFilePath(kOrigin2, kDB2).DirName();
602 602
603 tracker->DatabaseModified(kOrigin1, kDB1); 603 tracker->DatabaseModified(kOrigin1, kDB1);
604 tracker->DatabaseModified(kOrigin2, kDB2); 604 tracker->DatabaseModified(kOrigin2, kDB2);
605 605
606 // Close all databases. 606 // Close all databases.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, 663 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
664 &database_size); 664 &database_size);
665 EXPECT_EQ(0, database_size); 665 EXPECT_EQ(0, database_size);
666 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0, 666 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
667 &database_size); 667 &database_size);
668 EXPECT_EQ(0, database_size); 668 EXPECT_EQ(0, database_size);
669 669
670 // Write some data to each file. 670 // Write some data to each file.
671 base::FilePath db_file; 671 base::FilePath db_file;
672 db_file = tracker->GetFullDBFilePath(kOrigin1, kDB1); 672 db_file = tracker->GetFullDBFilePath(kOrigin1, kDB1);
673 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); 673 EXPECT_TRUE(base::CreateDirectory(db_file.DirName()));
674 EXPECT_TRUE(EnsureFileOfSize(db_file, 1)); 674 EXPECT_TRUE(EnsureFileOfSize(db_file, 1));
675 675
676 db_file = tracker->GetFullDBFilePath(kOrigin2, kDB2); 676 db_file = tracker->GetFullDBFilePath(kOrigin2, kDB2);
677 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); 677 EXPECT_TRUE(base::CreateDirectory(db_file.DirName()));
678 EXPECT_TRUE(EnsureFileOfSize(db_file, 2)); 678 EXPECT_TRUE(EnsureFileOfSize(db_file, 2));
679 679
680 // Store the origin database directories as long as they still exist. 680 // Store the origin database directories as long as they still exist.
681 origin1_db_dir = tracker->GetFullDBFilePath(kOrigin1, kDB1).DirName(); 681 origin1_db_dir = tracker->GetFullDBFilePath(kOrigin1, kDB1).DirName();
682 origin2_db_dir = tracker->GetFullDBFilePath(kOrigin2, kDB2).DirName(); 682 origin2_db_dir = tracker->GetFullDBFilePath(kOrigin2, kDB2).DirName();
683 683
684 tracker->DatabaseModified(kOrigin1, kDB1); 684 tracker->DatabaseModified(kOrigin1, kDB1);
685 tracker->DatabaseModified(kOrigin2, kDB2); 685 tracker->DatabaseModified(kOrigin2, kDB2);
686 686
687 // Close all databases. 687 // Close all databases.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 EXPECT_FALSE(observer.DidReceiveNewNotification()); 783 EXPECT_FALSE(observer.DidReceiveNewNotification());
784 784
785 // -------------------------------------------------------- 785 // --------------------------------------------------------
786 // Create a record of a database in the tracker db and create 786 // Create a record of a database in the tracker db and create
787 // a spoof_db_file on disk in the expected location. 787 // a spoof_db_file on disk in the expected location.
788 int64 database_size = 0; 788 int64 database_size = 0;
789 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0, 789 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0,
790 &database_size); 790 &database_size);
791 base::FilePath spoof_db_file = tracker->GetFullDBFilePath(kOriginId, kName); 791 base::FilePath spoof_db_file = tracker->GetFullDBFilePath(kOriginId, kName);
792 EXPECT_FALSE(tracker->GetFullDBFilePath(kOriginId, kName).empty()); 792 EXPECT_FALSE(tracker->GetFullDBFilePath(kOriginId, kName).empty());
793 EXPECT_TRUE(file_util::CreateDirectory(spoof_db_file.DirName())); 793 EXPECT_TRUE(base::CreateDirectory(spoof_db_file.DirName()));
794 EXPECT_TRUE(EnsureFileOfSize(spoof_db_file, 1)); 794 EXPECT_TRUE(EnsureFileOfSize(spoof_db_file, 1));
795 795
796 // Verify does no harm with a non-error is reported. 796 // Verify does no harm with a non-error is reported.
797 tracker->HandleSqliteError(kOriginId, kName, SQLITE_OK); 797 tracker->HandleSqliteError(kOriginId, kName, SQLITE_OK);
798 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName)); 798 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName));
799 EXPECT_FALSE(observer.DidReceiveNewNotification()); 799 EXPECT_FALSE(observer.DidReceiveNewNotification());
800 800
801 // Verify that with a connection open, the db is scheduled for deletion, 801 // Verify that with a connection open, the db is scheduled for deletion,
802 // but that the file still exists. 802 // but that the file still exists.
803 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT); 803 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT);
804 EXPECT_TRUE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName)); 804 EXPECT_TRUE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName));
805 EXPECT_TRUE(observer.DidReceiveNewNotification()); 805 EXPECT_TRUE(observer.DidReceiveNewNotification());
806 EXPECT_TRUE(base::PathExists(spoof_db_file)); 806 EXPECT_TRUE(base::PathExists(spoof_db_file));
807 807
808 // Verify that once closed, the file is deleted and the record in the 808 // Verify that once closed, the file is deleted and the record in the
809 // tracker db is removed. 809 // tracker db is removed.
810 tracker->DatabaseClosed(kOriginId, kName); 810 tracker->DatabaseClosed(kOriginId, kName);
811 EXPECT_FALSE(base::PathExists(spoof_db_file)); 811 EXPECT_FALSE(base::PathExists(spoof_db_file));
812 EXPECT_TRUE(tracker->GetFullDBFilePath(kOriginId, kName).empty()); 812 EXPECT_TRUE(tracker->GetFullDBFilePath(kOriginId, kName).empty());
813 813
814 // -------------------------------------------------------- 814 // --------------------------------------------------------
815 // Create another record of a database in the tracker db and create 815 // Create another record of a database in the tracker db and create
816 // a spoof_db_file on disk in the expected location. 816 // a spoof_db_file on disk in the expected location.
817 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0, 817 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0,
818 &database_size); 818 &database_size);
819 base::FilePath spoof_db_file2 = tracker->GetFullDBFilePath(kOriginId, kName) ; 819 base::FilePath spoof_db_file2 = tracker->GetFullDBFilePath(kOriginId, kName) ;
820 EXPECT_FALSE(tracker->GetFullDBFilePath(kOriginId, kName).empty()); 820 EXPECT_FALSE(tracker->GetFullDBFilePath(kOriginId, kName).empty());
821 EXPECT_NE(spoof_db_file, spoof_db_file2); 821 EXPECT_NE(spoof_db_file, spoof_db_file2);
822 EXPECT_TRUE(file_util::CreateDirectory(spoof_db_file2.DirName())); 822 EXPECT_TRUE(base::CreateDirectory(spoof_db_file2.DirName()));
823 EXPECT_TRUE(EnsureFileOfSize(spoof_db_file2, 1)); 823 EXPECT_TRUE(EnsureFileOfSize(spoof_db_file2, 1));
824 824
825 // Verify that with no connection open, the db is deleted immediately. 825 // Verify that with no connection open, the db is deleted immediately.
826 tracker->DatabaseClosed(kOriginId, kName); 826 tracker->DatabaseClosed(kOriginId, kName);
827 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT); 827 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT);
828 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName)); 828 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName));
829 EXPECT_FALSE(observer.DidReceiveNewNotification()); 829 EXPECT_FALSE(observer.DidReceiveNewNotification());
830 EXPECT_TRUE(tracker->GetFullDBFilePath(kOriginId, kName).empty()); 830 EXPECT_TRUE(tracker->GetFullDBFilePath(kOriginId, kName).empty());
831 EXPECT_FALSE(base::PathExists(spoof_db_file2)); 831 EXPECT_FALSE(base::PathExists(spoof_db_file2));
832 832
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 868
869 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) { 869 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) {
870 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid(); 870 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid();
871 } 871 }
872 872
873 TEST(DatabaseTrackerTest, HandleSqliteError) { 873 TEST(DatabaseTrackerTest, HandleSqliteError) {
874 DatabaseTracker_TestHelper_Test::HandleSqliteError(); 874 DatabaseTracker_TestHelper_Test::HandleSqliteError();
875 } 875 }
876 876
877 } // namespace webkit_database 877 } // namespace webkit_database
OLDNEW
« no previous file with comments | « webkit/browser/database/database_tracker.cc ('k') | webkit/browser/database/vfs_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698