OLD | NEW |
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.h" | 6 #include "base/files/file.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 &database_size); | 222 &database_size); |
223 tracker->DatabaseOpened(kOrigin2, kDB3, kDescription, 0, | 223 tracker->DatabaseOpened(kOrigin2, kDB3, kDescription, 0, |
224 &database_size); | 224 &database_size); |
225 | 225 |
226 EXPECT_TRUE(base::CreateDirectory( | 226 EXPECT_TRUE(base::CreateDirectory( |
227 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( | 227 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( |
228 tracker->GetOriginDirectory(kOrigin1))))); | 228 tracker->GetOriginDirectory(kOrigin1))))); |
229 EXPECT_TRUE(base::CreateDirectory( | 229 EXPECT_TRUE(base::CreateDirectory( |
230 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( | 230 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( |
231 tracker->GetOriginDirectory(kOrigin2))))); | 231 tracker->GetOriginDirectory(kOrigin2))))); |
232 EXPECT_EQ(1, file_util::WriteFile( | 232 EXPECT_EQ(1, base::WriteFile( |
233 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1)); | 233 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1)); |
234 EXPECT_EQ(2, file_util::WriteFile( | 234 EXPECT_EQ(2, base::WriteFile( |
235 tracker->GetFullDBFilePath(kOrigin2, kDB2), "aa", 2)); | 235 tracker->GetFullDBFilePath(kOrigin2, kDB2), "aa", 2)); |
236 EXPECT_EQ(3, file_util::WriteFile( | 236 EXPECT_EQ(3, base::WriteFile( |
237 tracker->GetFullDBFilePath(kOrigin2, kDB3), "aaa", 3)); | 237 tracker->GetFullDBFilePath(kOrigin2, kDB3), "aaa", 3)); |
238 tracker->DatabaseModified(kOrigin1, kDB1); | 238 tracker->DatabaseModified(kOrigin1, kDB1); |
239 tracker->DatabaseModified(kOrigin2, kDB2); | 239 tracker->DatabaseModified(kOrigin2, kDB2); |
240 tracker->DatabaseModified(kOrigin2, kDB3); | 240 tracker->DatabaseModified(kOrigin2, kDB3); |
241 | 241 |
242 // Delete db1. Should also delete origin1. | 242 // Delete db1. Should also delete origin1. |
243 TestObserver observer; | 243 TestObserver observer; |
244 tracker->AddObserver(&observer); | 244 tracker->AddObserver(&observer); |
245 net::TestCompletionCallback callback; | 245 net::TestCompletionCallback callback; |
246 int result = tracker->DeleteDatabase(kOrigin1, kDB1, callback.callback()); | 246 int result = tracker->DeleteDatabase(kOrigin1, kDB1, callback.callback()); |
247 EXPECT_EQ(net::ERR_IO_PENDING, result); | 247 EXPECT_EQ(net::ERR_IO_PENDING, result); |
248 ASSERT_FALSE(callback.have_result()); | 248 ASSERT_FALSE(callback.have_result()); |
249 EXPECT_TRUE(observer.DidReceiveNewNotification()); | 249 EXPECT_TRUE(observer.DidReceiveNewNotification()); |
250 EXPECT_EQ(kOrigin1, observer.GetNotificationOriginIdentifier()); | 250 EXPECT_EQ(kOrigin1, observer.GetNotificationOriginIdentifier()); |
251 EXPECT_EQ(kDB1, observer.GetNotificationDatabaseName()); | 251 EXPECT_EQ(kDB1, observer.GetNotificationDatabaseName()); |
252 tracker->DatabaseClosed(kOrigin1, kDB1); | 252 tracker->DatabaseClosed(kOrigin1, kDB1); |
253 result = callback.GetResult(result); | 253 result = callback.GetResult(result); |
254 EXPECT_EQ(net::OK, result); | 254 EXPECT_EQ(net::OK, result); |
255 EXPECT_FALSE(base::PathExists( | 255 EXPECT_FALSE(base::PathExists( |
256 tracker->DatabaseDirectory().AppendASCII(kOrigin1))); | 256 tracker->DatabaseDirectory().AppendASCII(kOrigin1))); |
257 | 257 |
258 // Recreate db1. | 258 // Recreate db1. |
259 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, | 259 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, |
260 &database_size); | 260 &database_size); |
261 EXPECT_TRUE(base::CreateDirectory( | 261 EXPECT_TRUE(base::CreateDirectory( |
262 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( | 262 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( |
263 tracker->GetOriginDirectory(kOrigin1))))); | 263 tracker->GetOriginDirectory(kOrigin1))))); |
264 EXPECT_EQ(1, file_util::WriteFile( | 264 EXPECT_EQ(1, base::WriteFile( |
265 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1)); | 265 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1)); |
266 tracker->DatabaseModified(kOrigin1, kDB1); | 266 tracker->DatabaseModified(kOrigin1, kDB1); |
267 | 267 |
268 // Setup file modification times. db1 and db2 are modified now, db3 three | 268 // Setup file modification times. db1 and db2 are modified now, db3 three |
269 // days ago. | 269 // days ago. |
270 base::Time now = base::Time::Now(); | 270 base::Time now = base::Time::Now(); |
271 EXPECT_TRUE(base::TouchFile(tracker->GetFullDBFilePath(kOrigin1, kDB1), | 271 EXPECT_TRUE(base::TouchFile(tracker->GetFullDBFilePath(kOrigin1, kDB1), |
272 now, now)); | 272 now, now)); |
273 EXPECT_TRUE(base::TouchFile(tracker->GetFullDBFilePath(kOrigin2, kDB2), | 273 EXPECT_TRUE(base::TouchFile(tracker->GetFullDBFilePath(kOrigin2, kDB2), |
274 now, now)); | 274 now, now)); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 EXPECT_EQ(0, database_size); | 350 EXPECT_EQ(0, database_size); |
351 | 351 |
352 // Write some data to each file and check that the listeners are | 352 // Write some data to each file and check that the listeners are |
353 // called with the appropriate values. | 353 // called with the appropriate values. |
354 EXPECT_TRUE(base::CreateDirectory( | 354 EXPECT_TRUE(base::CreateDirectory( |
355 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( | 355 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( |
356 tracker->GetOriginDirectory(kOrigin1))))); | 356 tracker->GetOriginDirectory(kOrigin1))))); |
357 EXPECT_TRUE(base::CreateDirectory( | 357 EXPECT_TRUE(base::CreateDirectory( |
358 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( | 358 tracker->DatabaseDirectory().Append(base::FilePath::FromUTF16Unsafe( |
359 tracker->GetOriginDirectory(kOrigin2))))); | 359 tracker->GetOriginDirectory(kOrigin2))))); |
360 EXPECT_EQ(1, file_util::WriteFile( | 360 EXPECT_EQ(1, base::WriteFile( |
361 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1)); | 361 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1)); |
362 EXPECT_EQ(2, file_util::WriteFile( | 362 EXPECT_EQ(2, base::WriteFile( |
363 tracker->GetFullDBFilePath(kOrigin2, kDB2), "aa", 2)); | 363 tracker->GetFullDBFilePath(kOrigin2, kDB2), "aa", 2)); |
364 EXPECT_EQ(4, file_util::WriteFile( | 364 EXPECT_EQ(4, base::WriteFile( |
365 tracker->GetFullDBFilePath(kOrigin1, kDB3), "aaaa", 4)); | 365 tracker->GetFullDBFilePath(kOrigin1, kDB3), "aaaa", 4)); |
366 tracker->DatabaseModified(kOrigin1, kDB1); | 366 tracker->DatabaseModified(kOrigin1, kDB1); |
367 CheckNotificationReceived(&observer1, kOrigin1, kDB1, 1); | 367 CheckNotificationReceived(&observer1, kOrigin1, kDB1, 1); |
368 CheckNotificationReceived(&observer2, kOrigin1, kDB1, 1); | 368 CheckNotificationReceived(&observer2, kOrigin1, kDB1, 1); |
369 tracker->DatabaseModified(kOrigin2, kDB2); | 369 tracker->DatabaseModified(kOrigin2, kDB2); |
370 CheckNotificationReceived(&observer1, kOrigin2, kDB2, 2); | 370 CheckNotificationReceived(&observer1, kOrigin2, kDB2, 2); |
371 CheckNotificationReceived(&observer2, kOrigin2, kDB2, 2); | 371 CheckNotificationReceived(&observer2, kOrigin2, kDB2, 2); |
372 tracker->DatabaseModified(kOrigin1, kDB3); | 372 tracker->DatabaseModified(kOrigin1, kDB3); |
373 CheckNotificationReceived(&observer1, kOrigin1, kDB3, 4); | 373 CheckNotificationReceived(&observer1, kOrigin1, kDB3, 4); |
374 CheckNotificationReceived(&observer2, kOrigin1, kDB3, 4); | 374 CheckNotificationReceived(&observer2, kOrigin1, kDB3, 4); |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 | 862 |
863 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) { | 863 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) { |
864 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid(); | 864 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid(); |
865 } | 865 } |
866 | 866 |
867 TEST(DatabaseTrackerTest, HandleSqliteError) { | 867 TEST(DatabaseTrackerTest, HandleSqliteError) { |
868 DatabaseTracker_TestHelper_Test::HandleSqliteError(); | 868 DatabaseTracker_TestHelper_Test::HandleSqliteError(); |
869 } | 869 } |
870 | 870 |
871 } // namespace webkit_database | 871 } // namespace webkit_database |
OLD | NEW |