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

Side by Side Diff: webkit/browser/fileapi/sandbox_prioritized_origin_database_unittest.cc

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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/fileapi/local_file_stream_writer_unittest.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/basictypes.h" 5 #include "base/basictypes.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/platform_file.h" 8 #include "base/platform_file.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "webkit/browser/fileapi/sandbox_origin_database.h" 10 #include "webkit/browser/fileapi/sandbox_origin_database.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 EXPECT_TRUE(database.GetPathForOrigin(kOrigin1, &path)); 116 EXPECT_TRUE(database.GetPathForOrigin(kOrigin1, &path));
117 117
118 // Reset the database. 118 // Reset the database.
119 database.DropDatabase(); 119 database.DropDatabase();
120 120
121 // kOrigin1 should still be marked as primary. 121 // kOrigin1 should still be marked as primary.
122 EXPECT_TRUE(database.HasOriginPath(kOrigin1)); 122 EXPECT_TRUE(database.HasOriginPath(kOrigin1));
123 EXPECT_TRUE(database.GetPathForOrigin(kOrigin1, &path)); 123 EXPECT_TRUE(database.GetPathForOrigin(kOrigin1, &path));
124 124
125 // Corrupt the primary origin file. 125 // Corrupt the primary origin file.
126 file_util::WriteFile( 126 base::WriteFile(database.primary_origin_file(), kData.data(), kData.size());
127 database.primary_origin_file(), kData.data(), kData.size());
128 127
129 // Reset the database. 128 // Reset the database.
130 database.DropDatabase(); 129 database.DropDatabase();
131 130
132 // kOrigin1 is no longer marked as primary, and unfortunately we fail 131 // kOrigin1 is no longer marked as primary, and unfortunately we fail
133 // to find the data for the origin. 132 // to find the data for the origin.
134 EXPECT_FALSE(database.HasOriginPath(kOrigin1)); 133 EXPECT_FALSE(database.HasOriginPath(kOrigin1));
135 } 134 }
136 135
137 TEST(SandboxPrioritizedOriginDatabaseTest, MigrationTest) { 136 TEST(SandboxPrioritizedOriginDatabaseTest, MigrationTest) {
(...skipping 19 matching lines...) Expand all
157 EXPECT_FALSE(path1.empty()); 156 EXPECT_FALSE(path1.empty());
158 EXPECT_TRUE(database_old.GetPathForOrigin(kOrigin2, &path2)); 157 EXPECT_TRUE(database_old.GetPathForOrigin(kOrigin2, &path2));
159 EXPECT_FALSE(path2.empty()); 158 EXPECT_FALSE(path2.empty());
160 159
161 EXPECT_TRUE(base::DirectoryExists(old_db_path)); 160 EXPECT_TRUE(base::DirectoryExists(old_db_path));
162 161
163 // Populate the origin directory with some fake data. 162 // Populate the origin directory with some fake data.
164 old_dir_db_path1 = dir.path().Append(path1); 163 old_dir_db_path1 = dir.path().Append(path1);
165 ASSERT_TRUE(base::CreateDirectory(old_dir_db_path1)); 164 ASSERT_TRUE(base::CreateDirectory(old_dir_db_path1));
166 EXPECT_EQ(static_cast<int>(kFakeDirectoryData1.size()), 165 EXPECT_EQ(static_cast<int>(kFakeDirectoryData1.size()),
167 file_util::WriteFile(old_dir_db_path1.AppendASCII("dummy"), 166 base::WriteFile(old_dir_db_path1.AppendASCII("dummy"),
168 kFakeDirectoryData1.data(), 167 kFakeDirectoryData1.data(),
169 kFakeDirectoryData1.size())); 168 kFakeDirectoryData1.size()));
170 old_dir_db_path2 = dir.path().Append(path2); 169 old_dir_db_path2 = dir.path().Append(path2);
171 ASSERT_TRUE(base::CreateDirectory(old_dir_db_path2)); 170 ASSERT_TRUE(base::CreateDirectory(old_dir_db_path2));
172 EXPECT_EQ(static_cast<int>(kFakeDirectoryData2.size()), 171 EXPECT_EQ(static_cast<int>(kFakeDirectoryData2.size()),
173 file_util::WriteFile(old_dir_db_path2.AppendASCII("dummy"), 172 base::WriteFile(old_dir_db_path2.AppendASCII("dummy"),
174 kFakeDirectoryData2.data(), 173 kFakeDirectoryData2.data(),
175 kFakeDirectoryData2.size())); 174 kFakeDirectoryData2.size()));
176 } 175 }
177 176
178 // Re-open the directory using sandboxPrioritizedOriginDatabase. 177 // Re-open the directory using sandboxPrioritizedOriginDatabase.
179 SandboxPrioritizedOriginDatabase database(dir.path(), NULL); 178 SandboxPrioritizedOriginDatabase database(dir.path(), NULL);
180 179
181 // Set the kOrigin1 as a parimary origin. 180 // Set the kOrigin1 as a parimary origin.
182 // (Trying to initialize another origin should fail). 181 // (Trying to initialize another origin should fail).
183 EXPECT_TRUE(database.InitializePrimaryOrigin(kOrigin1)); 182 EXPECT_TRUE(database.InitializePrimaryOrigin(kOrigin1));
184 EXPECT_FALSE(database.InitializePrimaryOrigin(kOrigin2)); 183 EXPECT_FALSE(database.InitializePrimaryOrigin(kOrigin2));
185 184
(...skipping 20 matching lines...) Expand all
206 EXPECT_TRUE(base::ReadFileToString( 205 EXPECT_TRUE(base::ReadFileToString(
207 dir_db_path.AppendASCII("dummy"), &origin_db_data)); 206 dir_db_path.AppendASCII("dummy"), &origin_db_data));
208 EXPECT_EQ(kFakeDirectoryData2, origin_db_data); 207 EXPECT_EQ(kFakeDirectoryData2, origin_db_data);
209 208
210 // After the migration the kOrigin1 directory database path must be gone. 209 // After the migration the kOrigin1 directory database path must be gone.
211 EXPECT_FALSE(base::PathExists(old_dir_db_path1)); 210 EXPECT_FALSE(base::PathExists(old_dir_db_path1));
212 EXPECT_TRUE(base::PathExists(old_dir_db_path2)); 211 EXPECT_TRUE(base::PathExists(old_dir_db_path2));
213 } 212 }
214 213
215 } // namespace fileapi 214 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/local_file_stream_writer_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698