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

Side by Side Diff: webkit/browser/appcache/appcache_database_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
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/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "sql/connection.h" 9 #include "sql/connection.h"
10 #include "sql/meta_table.h" 10 #include "sql/meta_table.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); 59 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db");
60 const base::FilePath kNestedDir = temp_dir.path().AppendASCII("nested"); 60 const base::FilePath kNestedDir = temp_dir.path().AppendASCII("nested");
61 const base::FilePath kOtherFile = kNestedDir.AppendASCII("other_file"); 61 const base::FilePath kOtherFile = kNestedDir.AppendASCII("other_file");
62 EXPECT_TRUE(file_util::CreateDirectory(kNestedDir)); 62 EXPECT_TRUE(file_util::CreateDirectory(kNestedDir));
63 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); 63 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3));
64 64
65 AppCacheDatabase db(kDbFile); 65 AppCacheDatabase db(kDbFile);
66 EXPECT_FALSE(db.LazyOpen(false)); 66 EXPECT_FALSE(db.LazyOpen(false));
67 EXPECT_TRUE(db.LazyOpen(true)); 67 EXPECT_TRUE(db.LazyOpen(true));
68 68
69 EXPECT_TRUE(file_util::PathExists(kDbFile)); 69 EXPECT_TRUE(base::PathExists(kDbFile));
70 EXPECT_TRUE(file_util::DirectoryExists(kNestedDir)); 70 EXPECT_TRUE(file_util::DirectoryExists(kNestedDir));
71 EXPECT_TRUE(file_util::PathExists(kOtherFile)); 71 EXPECT_TRUE(base::PathExists(kOtherFile));
72 72
73 EXPECT_TRUE(db.DeleteExistingAndCreateNewDatabase()); 73 EXPECT_TRUE(db.DeleteExistingAndCreateNewDatabase());
74 74
75 EXPECT_TRUE(file_util::PathExists(kDbFile)); 75 EXPECT_TRUE(base::PathExists(kDbFile));
76 EXPECT_FALSE(file_util::DirectoryExists(kNestedDir)); 76 EXPECT_FALSE(file_util::DirectoryExists(kNestedDir));
77 EXPECT_FALSE(file_util::PathExists(kOtherFile)); 77 EXPECT_FALSE(base::PathExists(kOtherFile));
78 } 78 }
79 79
80 TEST(AppCacheDatabaseTest, ExperimentalFlags) { 80 TEST(AppCacheDatabaseTest, ExperimentalFlags) {
81 const char kExperimentFlagsKey[] = "ExperimentFlags"; 81 const char kExperimentFlagsKey[] = "ExperimentFlags";
82 std::string kInjectedFlags("exp1,exp2"); 82 std::string kInjectedFlags("exp1,exp2");
83 83
84 // Real files on disk for this test. 84 // Real files on disk for this test.
85 base::ScopedTempDir temp_dir; 85 base::ScopedTempDir temp_dir;
86 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 86 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
87 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db"); 87 const base::FilePath kDbFile = temp_dir.path().AppendASCII("appcache.db");
88 const base::FilePath kOtherFile = temp_dir.path().AppendASCII("other_file"); 88 const base::FilePath kOtherFile = temp_dir.path().AppendASCII("other_file");
89 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3)); 89 EXPECT_EQ(3, file_util::WriteFile(kOtherFile, "foo", 3));
90 EXPECT_TRUE(file_util::PathExists(kOtherFile)); 90 EXPECT_TRUE(base::PathExists(kOtherFile));
91 91
92 AppCacheDatabase db(kDbFile); 92 AppCacheDatabase db(kDbFile);
93 EXPECT_TRUE(db.LazyOpen(true)); 93 EXPECT_TRUE(db.LazyOpen(true));
94 94
95 // Inject a non empty flags value, and verify it got there. 95 // Inject a non empty flags value, and verify it got there.
96 EXPECT_TRUE(db.meta_table_->SetValue(kExperimentFlagsKey, kInjectedFlags)); 96 EXPECT_TRUE(db.meta_table_->SetValue(kExperimentFlagsKey, kInjectedFlags));
97 std::string flags; 97 std::string flags;
98 EXPECT_TRUE(db.meta_table_->GetValue(kExperimentFlagsKey, &flags)); 98 EXPECT_TRUE(db.meta_table_->GetValue(kExperimentFlagsKey, &flags));
99 EXPECT_EQ(kInjectedFlags, flags); 99 EXPECT_EQ(kInjectedFlags, flags);
100 db.CloseConnection(); 100 db.CloseConnection();
101 101
102 // If flags don't match the expected value, empty string by default, 102 // If flags don't match the expected value, empty string by default,
103 // the database should be recreated and other files should be cleared out. 103 // the database should be recreated and other files should be cleared out.
104 EXPECT_TRUE(db.LazyOpen(false)); 104 EXPECT_TRUE(db.LazyOpen(false));
105 EXPECT_TRUE(db.meta_table_->GetValue(kExperimentFlagsKey, &flags)); 105 EXPECT_TRUE(db.meta_table_->GetValue(kExperimentFlagsKey, &flags));
106 EXPECT_TRUE(flags.empty()); 106 EXPECT_TRUE(flags.empty());
107 EXPECT_FALSE(file_util::PathExists(kOtherFile)); 107 EXPECT_FALSE(base::PathExists(kOtherFile));
108 } 108 }
109 109
110 TEST(AppCacheDatabaseTest, EntryRecords) { 110 TEST(AppCacheDatabaseTest, EntryRecords) {
111 const base::FilePath kEmptyPath; 111 const base::FilePath kEmptyPath;
112 AppCacheDatabase db(kEmptyPath); 112 AppCacheDatabase db(kEmptyPath);
113 EXPECT_TRUE(db.LazyOpen(true)); 113 EXPECT_TRUE(db.LazyOpen(true));
114 114
115 db.db_->set_error_callback(base::Bind(&IgnoreDatabaseErrors)); 115 db.db_->set_error_callback(base::Bind(&IgnoreDatabaseErrors));
116 116
117 AppCacheDatabase::EntryRecord entry; 117 AppCacheDatabase::EntryRecord entry;
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 EXPECT_EQ(kMockOrigin, fallbacks[i].origin); 1103 EXPECT_EQ(kMockOrigin, fallbacks[i].origin);
1104 EXPECT_EQ(expected_namespace_url, fallbacks[i].namespace_.namespace_url); 1104 EXPECT_EQ(expected_namespace_url, fallbacks[i].namespace_.namespace_url);
1105 EXPECT_EQ(expected_target_url, fallbacks[i].namespace_.target_url); 1105 EXPECT_EQ(expected_target_url, fallbacks[i].namespace_.target_url);
1106 EXPECT_FALSE(fallbacks[i].namespace_.is_pattern); 1106 EXPECT_FALSE(fallbacks[i].namespace_.is_pattern);
1107 EXPECT_EQ(expected_whitelist_url, whitelists[i].namespace_url); 1107 EXPECT_EQ(expected_whitelist_url, whitelists[i].namespace_url);
1108 EXPECT_FALSE(whitelists[i].is_pattern); 1108 EXPECT_FALSE(whitelists[i].is_pattern);
1109 } 1109 }
1110 } 1110 }
1111 1111
1112 } // namespace appcache 1112 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/browser/appcache/appcache_database.cc ('k') | webkit/browser/database/database_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698