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

Side by Side Diff: sql/connection_unittest.cc

Issue 89523002: Move Posix file utils to the 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 | « sql/connection.cc ('k') | no next file » | 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/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "sql/connection.h" 9 #include "sql/connection.h"
10 #include "sql/meta_table.h" 10 #include "sql/meta_table.h"
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 // will need to be updated. 682 // will need to be updated.
683 EXPECT_TRUE(db().Execute("CREATE TABLE x (x)")); 683 EXPECT_TRUE(db().Execute("CREATE TABLE x (x)"));
684 684
685 base::FilePath journal(db_path().value() + FILE_PATH_LITERAL("-journal")); 685 base::FilePath journal(db_path().value() + FILE_PATH_LITERAL("-journal"));
686 int mode; 686 int mode;
687 687
688 // Given a permissive umask, the database is created with permissive 688 // Given a permissive umask, the database is created with permissive
689 // read access for the database and journal. 689 // read access for the database and journal.
690 ASSERT_TRUE(base::PathExists(db_path())); 690 ASSERT_TRUE(base::PathExists(db_path()));
691 ASSERT_TRUE(base::PathExists(journal)); 691 ASSERT_TRUE(base::PathExists(journal));
692 mode = file_util::FILE_PERMISSION_MASK; 692 mode = base::FILE_PERMISSION_MASK;
693 EXPECT_TRUE(file_util::GetPosixFilePermissions(db_path(), &mode)); 693 EXPECT_TRUE(base::GetPosixFilePermissions(db_path(), &mode));
694 ASSERT_NE((mode & file_util::FILE_PERMISSION_USER_MASK), mode); 694 ASSERT_NE((mode & base::FILE_PERMISSION_USER_MASK), mode);
695 mode = file_util::FILE_PERMISSION_MASK; 695 mode = base::FILE_PERMISSION_MASK;
696 EXPECT_TRUE(file_util::GetPosixFilePermissions(journal, &mode)); 696 EXPECT_TRUE(base::GetPosixFilePermissions(journal, &mode));
697 ASSERT_NE((mode & file_util::FILE_PERMISSION_USER_MASK), mode); 697 ASSERT_NE((mode & base::FILE_PERMISSION_USER_MASK), mode);
698 698
699 // Re-open with restricted permissions and verify that the modes 699 // Re-open with restricted permissions and verify that the modes
700 // changed for both the main database and the journal. 700 // changed for both the main database and the journal.
701 db().Close(); 701 db().Close();
702 db().set_restrict_to_user(); 702 db().set_restrict_to_user();
703 ASSERT_TRUE(db().Open(db_path())); 703 ASSERT_TRUE(db().Open(db_path()));
704 ASSERT_TRUE(base::PathExists(db_path())); 704 ASSERT_TRUE(base::PathExists(db_path()));
705 ASSERT_TRUE(base::PathExists(journal)); 705 ASSERT_TRUE(base::PathExists(journal));
706 mode = file_util::FILE_PERMISSION_MASK; 706 mode = base::FILE_PERMISSION_MASK;
707 EXPECT_TRUE(file_util::GetPosixFilePermissions(db_path(), &mode)); 707 EXPECT_TRUE(base::GetPosixFilePermissions(db_path(), &mode));
708 ASSERT_EQ((mode & file_util::FILE_PERMISSION_USER_MASK), mode); 708 ASSERT_EQ((mode & base::FILE_PERMISSION_USER_MASK), mode);
709 mode = file_util::FILE_PERMISSION_MASK; 709 mode = base::FILE_PERMISSION_MASK;
710 EXPECT_TRUE(file_util::GetPosixFilePermissions(journal, &mode)); 710 EXPECT_TRUE(base::GetPosixFilePermissions(journal, &mode));
711 ASSERT_EQ((mode & file_util::FILE_PERMISSION_USER_MASK), mode); 711 ASSERT_EQ((mode & base::FILE_PERMISSION_USER_MASK), mode);
712 712
713 // Delete and re-create the database, the restriction should still apply. 713 // Delete and re-create the database, the restriction should still apply.
714 db().Close(); 714 db().Close();
715 sql::Connection::Delete(db_path()); 715 sql::Connection::Delete(db_path());
716 ASSERT_TRUE(db().Open(db_path())); 716 ASSERT_TRUE(db().Open(db_path()));
717 ASSERT_TRUE(base::PathExists(db_path())); 717 ASSERT_TRUE(base::PathExists(db_path()));
718 ASSERT_FALSE(base::PathExists(journal)); 718 ASSERT_FALSE(base::PathExists(journal));
719 mode = file_util::FILE_PERMISSION_MASK; 719 mode = base::FILE_PERMISSION_MASK;
720 EXPECT_TRUE(file_util::GetPosixFilePermissions(db_path(), &mode)); 720 EXPECT_TRUE(base::GetPosixFilePermissions(db_path(), &mode));
721 ASSERT_EQ((mode & file_util::FILE_PERMISSION_USER_MASK), mode); 721 ASSERT_EQ((mode & base::FILE_PERMISSION_USER_MASK), mode);
722 722
723 // Verify that journal creation inherits the restriction. 723 // Verify that journal creation inherits the restriction.
724 EXPECT_TRUE(db().Execute("CREATE TABLE x (x)")); 724 EXPECT_TRUE(db().Execute("CREATE TABLE x (x)"));
725 ASSERT_TRUE(base::PathExists(journal)); 725 ASSERT_TRUE(base::PathExists(journal));
726 mode = file_util::FILE_PERMISSION_MASK; 726 mode = base::FILE_PERMISSION_MASK;
727 EXPECT_TRUE(file_util::GetPosixFilePermissions(journal, &mode)); 727 EXPECT_TRUE(base::GetPosixFilePermissions(journal, &mode));
728 ASSERT_EQ((mode & file_util::FILE_PERMISSION_USER_MASK), mode); 728 ASSERT_EQ((mode & base::FILE_PERMISSION_USER_MASK), mode);
729 } 729 }
730 #endif // defined(OS_POSIX) 730 #endif // defined(OS_POSIX)
731 731
732 // Test that errors start happening once Poison() is called. 732 // Test that errors start happening once Poison() is called.
733 TEST_F(SQLConnectionTest, Poison) { 733 TEST_F(SQLConnectionTest, Poison) {
734 EXPECT_TRUE(db().Execute("CREATE TABLE x (x)")); 734 EXPECT_TRUE(db().Execute("CREATE TABLE x (x)"));
735 735
736 // Before the Poison() call, things generally work. 736 // Before the Poison() call, things generally work.
737 EXPECT_TRUE(db().IsSQLValid("INSERT INTO x VALUES ('x')")); 737 EXPECT_TRUE(db().IsSQLValid("INSERT INTO x VALUES ('x')"));
738 EXPECT_TRUE(db().Execute("INSERT INTO x VALUES ('x')")); 738 EXPECT_TRUE(db().Execute("INSERT INTO x VALUES ('x')"));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 } 816 }
817 817
818 // Detach succeeds outside of a transaction. 818 // Detach succeeds outside of a transaction.
819 db().RollbackTransaction(); 819 db().RollbackTransaction();
820 EXPECT_TRUE(db().DetachDatabase(kAttachmentPoint)); 820 EXPECT_TRUE(db().DetachDatabase(kAttachmentPoint));
821 821
822 EXPECT_FALSE(db().IsSQLValid("SELECT count(*) from other.bar")); 822 EXPECT_FALSE(db().IsSQLValid("SELECT count(*) from other.bar"));
823 } 823 }
824 824
825 } // namespace 825 } // namespace
OLDNEW
« no previous file with comments | « sql/connection.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698