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

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

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | « 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.h" 9 #include "base/message_loop.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 net::TestCompletionCallback callback; 242 net::TestCompletionCallback callback;
243 int result = tracker->DeleteDatabase(kOrigin1, kDB1, callback.callback()); 243 int result = tracker->DeleteDatabase(kOrigin1, kDB1, callback.callback());
244 EXPECT_EQ(net::ERR_IO_PENDING, result); 244 EXPECT_EQ(net::ERR_IO_PENDING, result);
245 ASSERT_FALSE(callback.have_result()); 245 ASSERT_FALSE(callback.have_result());
246 EXPECT_TRUE(observer.DidReceiveNewNotification()); 246 EXPECT_TRUE(observer.DidReceiveNewNotification());
247 EXPECT_EQ(kOrigin1, observer.GetNotificationOriginIdentifier()); 247 EXPECT_EQ(kOrigin1, observer.GetNotificationOriginIdentifier());
248 EXPECT_EQ(kDB1, observer.GetNotificationDatabaseName()); 248 EXPECT_EQ(kDB1, observer.GetNotificationDatabaseName());
249 tracker->DatabaseClosed(kOrigin1, kDB1); 249 tracker->DatabaseClosed(kOrigin1, kDB1);
250 result = callback.GetResult(result); 250 result = callback.GetResult(result);
251 EXPECT_EQ(net::OK, result); 251 EXPECT_EQ(net::OK, result);
252 EXPECT_FALSE(file_util::PathExists( 252 EXPECT_FALSE(base::PathExists(
253 tracker->DatabaseDirectory().AppendASCII(kOrigin1))); 253 tracker->DatabaseDirectory().AppendASCII(kOrigin1)));
254 254
255 // Recreate db1. 255 // Recreate db1.
256 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, 256 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
257 &database_size); 257 &database_size);
258 EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append( 258 EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append(
259 base::FilePath::FromWStringHack(UTF16ToWide( 259 base::FilePath::FromWStringHack(UTF16ToWide(
260 tracker->GetOriginDirectory(kOrigin1)))))); 260 tracker->GetOriginDirectory(kOrigin1))))));
261 EXPECT_EQ(1, file_util::WriteFile( 261 EXPECT_EQ(1, file_util::WriteFile(
262 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1)); 262 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1));
(...skipping 15 matching lines...) Expand all
278 yesterday -= base::TimeDelta::FromDays(1); 278 yesterday -= base::TimeDelta::FromDays(1);
279 result = tracker->DeleteDataModifiedSince( 279 result = tracker->DeleteDataModifiedSince(
280 yesterday, callback.callback()); 280 yesterday, callback.callback());
281 EXPECT_EQ(net::ERR_IO_PENDING, result); 281 EXPECT_EQ(net::ERR_IO_PENDING, result);
282 ASSERT_FALSE(callback.have_result()); 282 ASSERT_FALSE(callback.have_result());
283 EXPECT_TRUE(observer.DidReceiveNewNotification()); 283 EXPECT_TRUE(observer.DidReceiveNewNotification());
284 tracker->DatabaseClosed(kOrigin1, kDB1); 284 tracker->DatabaseClosed(kOrigin1, kDB1);
285 tracker->DatabaseClosed(kOrigin2, kDB2); 285 tracker->DatabaseClosed(kOrigin2, kDB2);
286 result = callback.GetResult(result); 286 result = callback.GetResult(result);
287 EXPECT_EQ(net::OK, result); 287 EXPECT_EQ(net::OK, result);
288 EXPECT_FALSE(file_util::PathExists( 288 EXPECT_FALSE(base::PathExists(
289 tracker->DatabaseDirectory().AppendASCII(kOrigin1))); 289 tracker->DatabaseDirectory().AppendASCII(kOrigin1)));
290 EXPECT_TRUE( 290 EXPECT_TRUE(
291 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB2))); 291 base::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB2)));
292 EXPECT_TRUE( 292 EXPECT_TRUE(
293 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB3))); 293 base::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB3)));
294 294
295 tracker->DatabaseClosed(kOrigin2, kDB3); 295 tracker->DatabaseClosed(kOrigin2, kDB3);
296 tracker->RemoveObserver(&observer); 296 tracker->RemoveObserver(&observer);
297 } 297 }
298 298
299 static void TestDatabaseTracker(bool incognito_mode) { 299 static void TestDatabaseTracker(bool incognito_mode) {
300 // Initialize the tracker database. 300 // Initialize the tracker database.
301 base::ScopedTempDir temp_dir; 301 base::ScopedTempDir temp_dir;
302 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 302 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
303 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = 303 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 new DatabaseTracker(temp_dir.path(), false, NULL, NULL, NULL)); 606 new DatabaseTracker(temp_dir.path(), false, NULL, NULL, NULL));
607 607
608 // Get all data for all origins. 608 // Get all data for all origins.
609 std::vector<OriginInfo> origins_info; 609 std::vector<OriginInfo> origins_info;
610 EXPECT_TRUE(tracker->GetAllOriginsInfo(&origins_info)); 610 EXPECT_TRUE(tracker->GetAllOriginsInfo(&origins_info));
611 // kOrigin1 was not session-only, so it survived. kOrigin2 was session-only 611 // kOrigin1 was not session-only, so it survived. kOrigin2 was session-only
612 // and it got deleted. 612 // and it got deleted.
613 EXPECT_EQ(size_t(1), origins_info.size()); 613 EXPECT_EQ(size_t(1), origins_info.size());
614 EXPECT_EQ(kOrigin1, origins_info[0].GetOriginIdentifier()); 614 EXPECT_EQ(kOrigin1, origins_info[0].GetOriginIdentifier());
615 EXPECT_TRUE( 615 EXPECT_TRUE(
616 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin1, kDB1))); 616 base::PathExists(tracker->GetFullDBFilePath(kOrigin1, kDB1)));
617 EXPECT_EQ(base::FilePath(), tracker->GetFullDBFilePath(kOrigin2, kDB2)); 617 EXPECT_EQ(base::FilePath(), tracker->GetFullDBFilePath(kOrigin2, kDB2));
618 618
619 // The origin directory of kOrigin1 remains, but the origin directory of 619 // The origin directory of kOrigin1 remains, but the origin directory of
620 // kOrigin2 is deleted. 620 // kOrigin2 is deleted.
621 EXPECT_TRUE(file_util::PathExists(origin1_db_dir)); 621 EXPECT_TRUE(base::PathExists(origin1_db_dir));
622 EXPECT_FALSE(file_util::PathExists(origin2_db_dir)); 622 EXPECT_FALSE(base::PathExists(origin2_db_dir));
623 } 623 }
624 624
625 static void DatabaseTrackerSetForceKeepSessionState() { 625 static void DatabaseTrackerSetForceKeepSessionState() {
626 int64 database_size = 0; 626 int64 database_size = 0;
627 const std::string kOrigin1 = 627 const std::string kOrigin1 =
628 webkit_database::GetIdentifierFromOrigin(GURL(kOrigin1Url)); 628 webkit_database::GetIdentifierFromOrigin(GURL(kOrigin1Url));
629 const std::string kOrigin2 = 629 const std::string kOrigin2 =
630 webkit_database::GetIdentifierFromOrigin(GURL(kOrigin2Url)); 630 webkit_database::GetIdentifierFromOrigin(GURL(kOrigin2Url));
631 const base::string16 kDB1 = ASCIIToUTF16("db1"); 631 const base::string16 kDB1 = ASCIIToUTF16("db1");
632 const base::string16 kDB2 = ASCIIToUTF16("db2"); 632 const base::string16 kDB2 = ASCIIToUTF16("db2");
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 // At this point, the database tracker should be gone. Create a new one. 685 // At this point, the database tracker should be gone. Create a new one.
686 scoped_refptr<DatabaseTracker> tracker( 686 scoped_refptr<DatabaseTracker> tracker(
687 new DatabaseTracker(temp_dir.path(), false, NULL, NULL, NULL)); 687 new DatabaseTracker(temp_dir.path(), false, NULL, NULL, NULL));
688 688
689 // Get all data for all origins. 689 // Get all data for all origins.
690 std::vector<OriginInfo> origins_info; 690 std::vector<OriginInfo> origins_info;
691 EXPECT_TRUE(tracker->GetAllOriginsInfo(&origins_info)); 691 EXPECT_TRUE(tracker->GetAllOriginsInfo(&origins_info));
692 // No origins were deleted. 692 // No origins were deleted.
693 EXPECT_EQ(size_t(2), origins_info.size()); 693 EXPECT_EQ(size_t(2), origins_info.size());
694 EXPECT_TRUE( 694 EXPECT_TRUE(
695 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin1, kDB1))); 695 base::PathExists(tracker->GetFullDBFilePath(kOrigin1, kDB1)));
696 EXPECT_TRUE( 696 EXPECT_TRUE(
697 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB2))); 697 base::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB2)));
698 698
699 EXPECT_TRUE(file_util::PathExists(origin1_db_dir)); 699 EXPECT_TRUE(base::PathExists(origin1_db_dir));
700 EXPECT_TRUE(file_util::PathExists(origin2_db_dir)); 700 EXPECT_TRUE(base::PathExists(origin2_db_dir));
701 } 701 }
702 702
703 static void EmptyDatabaseNameIsValid() { 703 static void EmptyDatabaseNameIsValid() {
704 const GURL kOrigin(kOrigin1Url); 704 const GURL kOrigin(kOrigin1Url);
705 const std::string kOriginId = 705 const std::string kOriginId =
706 webkit_database::GetIdentifierFromOrigin(kOrigin); 706 webkit_database::GetIdentifierFromOrigin(kOrigin);
707 const base::string16 kEmptyName; 707 const base::string16 kEmptyName;
708 const base::string16 kDescription(ASCIIToUTF16("description")); 708 const base::string16 kDescription(ASCIIToUTF16("description"));
709 const base::string16 kChangedDescription( 709 const base::string16 kChangedDescription(
710 ASCIIToUTF16("changed_description")); 710 ASCIIToUTF16("changed_description"));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 // Verify does no harm with a non-error is reported. 787 // Verify does no harm with a non-error is reported.
788 tracker->HandleSqliteError(kOriginId, kName, SQLITE_OK); 788 tracker->HandleSqliteError(kOriginId, kName, SQLITE_OK);
789 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName)); 789 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName));
790 EXPECT_FALSE(observer.DidReceiveNewNotification()); 790 EXPECT_FALSE(observer.DidReceiveNewNotification());
791 791
792 // Verify that with a connection open, the db is scheduled for deletion, 792 // Verify that with a connection open, the db is scheduled for deletion,
793 // but that the file still exists. 793 // but that the file still exists.
794 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT); 794 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT);
795 EXPECT_TRUE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName)); 795 EXPECT_TRUE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName));
796 EXPECT_TRUE(observer.DidReceiveNewNotification()); 796 EXPECT_TRUE(observer.DidReceiveNewNotification());
797 EXPECT_TRUE(file_util::PathExists(spoof_db_file)); 797 EXPECT_TRUE(base::PathExists(spoof_db_file));
798 798
799 // Verify that once closed, the file is deleted and the record in the 799 // Verify that once closed, the file is deleted and the record in the
800 // tracker db is removed. 800 // tracker db is removed.
801 tracker->DatabaseClosed(kOriginId, kName); 801 tracker->DatabaseClosed(kOriginId, kName);
802 EXPECT_FALSE(file_util::PathExists(spoof_db_file)); 802 EXPECT_FALSE(base::PathExists(spoof_db_file));
803 EXPECT_TRUE(tracker->GetFullDBFilePath(kOriginId, kName).empty()); 803 EXPECT_TRUE(tracker->GetFullDBFilePath(kOriginId, kName).empty());
804 804
805 // -------------------------------------------------------- 805 // --------------------------------------------------------
806 // Create another record of a database in the tracker db and create 806 // Create another record of a database in the tracker db and create
807 // a spoof_db_file on disk in the expected location. 807 // a spoof_db_file on disk in the expected location.
808 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0, 808 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0,
809 &database_size); 809 &database_size);
810 base::FilePath spoof_db_file2 = tracker->GetFullDBFilePath(kOriginId, kName) ; 810 base::FilePath spoof_db_file2 = tracker->GetFullDBFilePath(kOriginId, kName) ;
811 EXPECT_FALSE(tracker->GetFullDBFilePath(kOriginId, kName).empty()); 811 EXPECT_FALSE(tracker->GetFullDBFilePath(kOriginId, kName).empty());
812 EXPECT_NE(spoof_db_file, spoof_db_file2); 812 EXPECT_NE(spoof_db_file, spoof_db_file2);
813 EXPECT_TRUE(file_util::CreateDirectory(spoof_db_file2.DirName())); 813 EXPECT_TRUE(file_util::CreateDirectory(spoof_db_file2.DirName()));
814 EXPECT_TRUE(EnsureFileOfSize(spoof_db_file2, 1)); 814 EXPECT_TRUE(EnsureFileOfSize(spoof_db_file2, 1));
815 815
816 // Verify that with no connection open, the db is deleted immediately. 816 // Verify that with no connection open, the db is deleted immediately.
817 tracker->DatabaseClosed(kOriginId, kName); 817 tracker->DatabaseClosed(kOriginId, kName);
818 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT); 818 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT);
819 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName)); 819 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName));
820 EXPECT_FALSE(observer.DidReceiveNewNotification()); 820 EXPECT_FALSE(observer.DidReceiveNewNotification());
821 EXPECT_TRUE(tracker->GetFullDBFilePath(kOriginId, kName).empty()); 821 EXPECT_TRUE(tracker->GetFullDBFilePath(kOriginId, kName).empty());
822 EXPECT_FALSE(file_util::PathExists(spoof_db_file2)); 822 EXPECT_FALSE(base::PathExists(spoof_db_file2));
823 823
824 tracker->RemoveObserver(&observer); 824 tracker->RemoveObserver(&observer);
825 } 825 }
826 }; 826 };
827 827
828 TEST(DatabaseTrackerTest, DeleteOpenDatabase) { 828 TEST(DatabaseTrackerTest, DeleteOpenDatabase) {
829 DatabaseTracker_TestHelper_Test::TestDeleteOpenDatabase(false); 829 DatabaseTracker_TestHelper_Test::TestDeleteOpenDatabase(false);
830 } 830 }
831 831
832 TEST(DatabaseTrackerTest, DeleteOpenDatabaseIncognitoMode) { 832 TEST(DatabaseTrackerTest, DeleteOpenDatabaseIncognitoMode) {
(...skipping 26 matching lines...) Expand all
859 859
860 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) { 860 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) {
861 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid(); 861 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid();
862 } 862 }
863 863
864 TEST(DatabaseTrackerTest, HandleSqliteError) { 864 TEST(DatabaseTrackerTest, HandleSqliteError) {
865 DatabaseTracker_TestHelper_Test::HandleSqliteError(); 865 DatabaseTracker_TestHelper_Test::HandleSqliteError();
866 } 866 }
867 867
868 } // namespace webkit_database 868 } // 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