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

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

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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/database/database_tracker.cc ('k') | webkit/database/database_util.h » ('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_path.h" 5 #include "base/file_path.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/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_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // Map from origin to <count, sum of deltas> 151 // Map from origin to <count, sum of deltas>
152 std::map<GURL, std::pair<int, int64> > modifications_; 152 std::map<GURL, std::pair<int, int64> > modifications_;
153 153
154 protected: 154 protected:
155 virtual ~TestQuotaManagerProxy() { 155 virtual ~TestQuotaManagerProxy() {
156 EXPECT_FALSE(registered_client_); 156 EXPECT_FALSE(registered_client_);
157 } 157 }
158 }; 158 };
159 159
160 160
161 bool EnsureFileOfSize(const FilePath& file_path, int64 length) { 161 bool EnsureFileOfSize(const base::FilePath& file_path, int64 length) {
162 base::PlatformFileError error_code(base::PLATFORM_FILE_ERROR_FAILED); 162 base::PlatformFileError error_code(base::PLATFORM_FILE_ERROR_FAILED);
163 base::PlatformFile file = 163 base::PlatformFile file =
164 base::CreatePlatformFile( 164 base::CreatePlatformFile(
165 file_path, 165 file_path,
166 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE, 166 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE,
167 NULL, 167 NULL,
168 &error_code); 168 &error_code);
169 if (error_code != base::PLATFORM_FILE_OK) 169 if (error_code != base::PLATFORM_FILE_OK)
170 return false; 170 return false;
171 if (!base::TruncatePlatformFile(file, length)) 171 if (!base::TruncatePlatformFile(file, length))
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 const string16 kDescription = ASCIIToUTF16("database_description"); 208 const string16 kDescription = ASCIIToUTF16("database_description");
209 209
210 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, 210 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
211 &database_size); 211 &database_size);
212 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0, 212 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
213 &database_size); 213 &database_size);
214 tracker->DatabaseOpened(kOrigin2, kDB3, kDescription, 0, 214 tracker->DatabaseOpened(kOrigin2, kDB3, kDescription, 0,
215 &database_size); 215 &database_size);
216 216
217 EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append( 217 EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append(
218 FilePath::FromWStringHack(UTF16ToWide( 218 base::FilePath::FromWStringHack(UTF16ToWide(
219 tracker->GetOriginDirectory(kOrigin1)))))); 219 tracker->GetOriginDirectory(kOrigin1))))));
220 EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append( 220 EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append(
221 FilePath::FromWStringHack(UTF16ToWide( 221 base::FilePath::FromWStringHack(UTF16ToWide(
222 tracker->GetOriginDirectory(kOrigin2)))))); 222 tracker->GetOriginDirectory(kOrigin2))))));
223 EXPECT_EQ(1, file_util::WriteFile( 223 EXPECT_EQ(1, file_util::WriteFile(
224 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1)); 224 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1));
225 EXPECT_EQ(2, file_util::WriteFile( 225 EXPECT_EQ(2, file_util::WriteFile(
226 tracker->GetFullDBFilePath(kOrigin2, kDB2), "aa", 2)); 226 tracker->GetFullDBFilePath(kOrigin2, kDB2), "aa", 2));
227 EXPECT_EQ(3, file_util::WriteFile( 227 EXPECT_EQ(3, file_util::WriteFile(
228 tracker->GetFullDBFilePath(kOrigin2, kDB3), "aaa", 3)); 228 tracker->GetFullDBFilePath(kOrigin2, kDB3), "aaa", 3));
229 tracker->DatabaseModified(kOrigin1, kDB1); 229 tracker->DatabaseModified(kOrigin1, kDB1);
230 tracker->DatabaseModified(kOrigin2, kDB2); 230 tracker->DatabaseModified(kOrigin2, kDB2);
231 tracker->DatabaseModified(kOrigin2, kDB3); 231 tracker->DatabaseModified(kOrigin2, kDB3);
232 232
233 // Delete db1. Should also delete origin1. 233 // Delete db1. Should also delete origin1.
234 TestObserver observer; 234 TestObserver observer;
235 tracker->AddObserver(&observer); 235 tracker->AddObserver(&observer);
236 net::TestCompletionCallback callback; 236 net::TestCompletionCallback callback;
237 int result = tracker->DeleteDatabase(kOrigin1, kDB1, callback.callback()); 237 int result = tracker->DeleteDatabase(kOrigin1, kDB1, callback.callback());
238 EXPECT_EQ(net::ERR_IO_PENDING, result); 238 EXPECT_EQ(net::ERR_IO_PENDING, result);
239 ASSERT_FALSE(callback.have_result()); 239 ASSERT_FALSE(callback.have_result());
240 EXPECT_TRUE(observer.DidReceiveNewNotification()); 240 EXPECT_TRUE(observer.DidReceiveNewNotification());
241 EXPECT_EQ(kOrigin1, observer.GetNotificationOriginIdentifier()); 241 EXPECT_EQ(kOrigin1, observer.GetNotificationOriginIdentifier());
242 EXPECT_EQ(kDB1, observer.GetNotificationDatabaseName()); 242 EXPECT_EQ(kDB1, observer.GetNotificationDatabaseName());
243 tracker->DatabaseClosed(kOrigin1, kDB1); 243 tracker->DatabaseClosed(kOrigin1, kDB1);
244 result = callback.GetResult(result); 244 result = callback.GetResult(result);
245 EXPECT_EQ(net::OK, result); 245 EXPECT_EQ(net::OK, result);
246 EXPECT_FALSE(file_util::PathExists(tracker->DatabaseDirectory().Append( 246 EXPECT_FALSE(file_util::PathExists(tracker->DatabaseDirectory().Append(
247 FilePath::FromWStringHack(UTF16ToWide(kOrigin1))))); 247 base::FilePath::FromWStringHack(UTF16ToWide(kOrigin1)))));
248 248
249 // Recreate db1. 249 // Recreate db1.
250 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, 250 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
251 &database_size); 251 &database_size);
252 EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append( 252 EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append(
253 FilePath::FromWStringHack(UTF16ToWide( 253 base::FilePath::FromWStringHack(UTF16ToWide(
254 tracker->GetOriginDirectory(kOrigin1)))))); 254 tracker->GetOriginDirectory(kOrigin1))))));
255 EXPECT_EQ(1, file_util::WriteFile( 255 EXPECT_EQ(1, file_util::WriteFile(
256 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1)); 256 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1));
257 tracker->DatabaseModified(kOrigin1, kDB1); 257 tracker->DatabaseModified(kOrigin1, kDB1);
258 258
259 // Setup file modification times. db1 and db2 are modified now, db3 three 259 // Setup file modification times. db1 and db2 are modified now, db3 three
260 // days ago. 260 // days ago.
261 EXPECT_TRUE(file_util::SetLastModifiedTime( 261 EXPECT_TRUE(file_util::SetLastModifiedTime(
262 tracker->GetFullDBFilePath(kOrigin1, kDB1), base::Time::Now())); 262 tracker->GetFullDBFilePath(kOrigin1, kDB1), base::Time::Now()));
263 EXPECT_TRUE(file_util::SetLastModifiedTime( 263 EXPECT_TRUE(file_util::SetLastModifiedTime(
264 tracker->GetFullDBFilePath(kOrigin2, kDB2), base::Time::Now())); 264 tracker->GetFullDBFilePath(kOrigin2, kDB2), base::Time::Now()));
265 base::Time three_days_ago = base::Time::Now(); 265 base::Time three_days_ago = base::Time::Now();
266 three_days_ago -= base::TimeDelta::FromDays(3); 266 three_days_ago -= base::TimeDelta::FromDays(3);
267 EXPECT_TRUE(file_util::SetLastModifiedTime( 267 EXPECT_TRUE(file_util::SetLastModifiedTime(
268 tracker->GetFullDBFilePath(kOrigin2, kDB3), three_days_ago)); 268 tracker->GetFullDBFilePath(kOrigin2, kDB3), three_days_ago));
269 269
270 // Delete databases modified since yesterday. db2 is whitelisted. 270 // Delete databases modified since yesterday. db2 is whitelisted.
271 base::Time yesterday = base::Time::Now(); 271 base::Time yesterday = base::Time::Now();
272 yesterday -= base::TimeDelta::FromDays(1); 272 yesterday -= base::TimeDelta::FromDays(1);
273 result = tracker->DeleteDataModifiedSince( 273 result = tracker->DeleteDataModifiedSince(
274 yesterday, callback.callback()); 274 yesterday, callback.callback());
275 EXPECT_EQ(net::ERR_IO_PENDING, result); 275 EXPECT_EQ(net::ERR_IO_PENDING, result);
276 ASSERT_FALSE(callback.have_result()); 276 ASSERT_FALSE(callback.have_result());
277 EXPECT_TRUE(observer.DidReceiveNewNotification()); 277 EXPECT_TRUE(observer.DidReceiveNewNotification());
278 tracker->DatabaseClosed(kOrigin1, kDB1); 278 tracker->DatabaseClosed(kOrigin1, kDB1);
279 tracker->DatabaseClosed(kOrigin2, kDB2); 279 tracker->DatabaseClosed(kOrigin2, kDB2);
280 result = callback.GetResult(result); 280 result = callback.GetResult(result);
281 EXPECT_EQ(net::OK, result); 281 EXPECT_EQ(net::OK, result);
282 EXPECT_FALSE(file_util::PathExists(tracker->DatabaseDirectory().Append( 282 EXPECT_FALSE(file_util::PathExists(tracker->DatabaseDirectory().Append(
283 FilePath::FromWStringHack(UTF16ToWide(kOrigin1))))); 283 base::FilePath::FromWStringHack(UTF16ToWide(kOrigin1)))));
284 EXPECT_TRUE( 284 EXPECT_TRUE(
285 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB2))); 285 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB2)));
286 EXPECT_TRUE( 286 EXPECT_TRUE(
287 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB3))); 287 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB3)));
288 288
289 tracker->DatabaseClosed(kOrigin2, kDB3); 289 tracker->DatabaseClosed(kOrigin2, kDB3);
290 tracker->RemoveObserver(&observer); 290 tracker->RemoveObserver(&observer);
291 } 291 }
292 292
293 static void TestDatabaseTracker(bool incognito_mode) { 293 static void TestDatabaseTracker(bool incognito_mode) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0, 333 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
334 &database_size); 334 &database_size);
335 EXPECT_EQ(0, database_size); 335 EXPECT_EQ(0, database_size);
336 tracker->DatabaseOpened(kOrigin1, kDB3, kDescription, 0, 336 tracker->DatabaseOpened(kOrigin1, kDB3, kDescription, 0,
337 &database_size); 337 &database_size);
338 EXPECT_EQ(0, database_size); 338 EXPECT_EQ(0, database_size);
339 339
340 // Write some data to each file and check that the listeners are 340 // Write some data to each file and check that the listeners are
341 // called with the appropriate values. 341 // called with the appropriate values.
342 EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append( 342 EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append(
343 FilePath::FromWStringHack(UTF16ToWide( 343 base::FilePath::FromWStringHack(UTF16ToWide(
344 tracker->GetOriginDirectory(kOrigin1)))))); 344 tracker->GetOriginDirectory(kOrigin1))))));
345 EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append( 345 EXPECT_TRUE(file_util::CreateDirectory(tracker->DatabaseDirectory().Append(
346 FilePath::FromWStringHack(UTF16ToWide( 346 base::FilePath::FromWStringHack(UTF16ToWide(
347 tracker->GetOriginDirectory(kOrigin2)))))); 347 tracker->GetOriginDirectory(kOrigin2))))));
348 EXPECT_EQ(1, file_util::WriteFile( 348 EXPECT_EQ(1, file_util::WriteFile(
349 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1)); 349 tracker->GetFullDBFilePath(kOrigin1, kDB1), "a", 1));
350 EXPECT_EQ(2, file_util::WriteFile( 350 EXPECT_EQ(2, file_util::WriteFile(
351 tracker->GetFullDBFilePath(kOrigin2, kDB2), "aa", 2)); 351 tracker->GetFullDBFilePath(kOrigin2, kDB2), "aa", 2));
352 EXPECT_EQ(4, file_util::WriteFile( 352 EXPECT_EQ(4, file_util::WriteFile(
353 tracker->GetFullDBFilePath(kOrigin1, kDB3), "aaaa", 4)); 353 tracker->GetFullDBFilePath(kOrigin1, kDB3), "aaaa", 4));
354 tracker->DatabaseModified(kOrigin1, kDB1); 354 tracker->DatabaseModified(kOrigin1, kDB1);
355 CheckNotificationReceived(&observer1, kOrigin1, kDB1, 1); 355 CheckNotificationReceived(&observer1, kOrigin1, kDB1, 1);
356 CheckNotificationReceived(&observer2, kOrigin1, kDB1, 1); 356 CheckNotificationReceived(&observer2, kOrigin1, kDB1, 1);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 454
455 // Create a database and modify it a couple of times, close it, 455 // Create a database and modify it a couple of times, close it,
456 // then delete it. Observe the tracker notifies accordingly. 456 // then delete it. Observe the tracker notifies accordingly.
457 457
458 int64 database_size = 0; 458 int64 database_size = 0;
459 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0, 459 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0,
460 &database_size); 460 &database_size);
461 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin)); 461 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin));
462 test_quota_proxy->reset(); 462 test_quota_proxy->reset();
463 463
464 FilePath db_file(tracker->GetFullDBFilePath(kOriginId, kName)); 464 base::FilePath db_file(tracker->GetFullDBFilePath(kOriginId, kName));
465 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); 465 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName()));
466 EXPECT_TRUE(EnsureFileOfSize(db_file, 10)); 466 EXPECT_TRUE(EnsureFileOfSize(db_file, 10));
467 tracker->DatabaseModified(kOriginId, kName); 467 tracker->DatabaseModified(kOriginId, kName);
468 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 10)); 468 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 10));
469 test_quota_proxy->reset(); 469 test_quota_proxy->reset();
470 470
471 EXPECT_TRUE(EnsureFileOfSize(db_file, 100)); 471 EXPECT_TRUE(EnsureFileOfSize(db_file, 100));
472 tracker->DatabaseModified(kOriginId, kName); 472 tracker->DatabaseModified(kOriginId, kName);
473 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 90)); 473 EXPECT_TRUE(test_quota_proxy->WasModificationNotified(kOrigin, 90));
474 test_quota_proxy->reset(); 474 test_quota_proxy->reset();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 const string16 kOrigin2 = 536 const string16 kOrigin2 =
537 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin2Url)); 537 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin2Url));
538 const string16 kDB1 = ASCIIToUTF16("db1"); 538 const string16 kDB1 = ASCIIToUTF16("db1");
539 const string16 kDB2 = ASCIIToUTF16("db2"); 539 const string16 kDB2 = ASCIIToUTF16("db2");
540 const string16 kDescription = ASCIIToUTF16("database_description"); 540 const string16 kDescription = ASCIIToUTF16("database_description");
541 541
542 // Initialize the tracker database. 542 // Initialize the tracker database.
543 MessageLoop message_loop; 543 MessageLoop message_loop;
544 base::ScopedTempDir temp_dir; 544 base::ScopedTempDir temp_dir;
545 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 545 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
546 FilePath origin1_db_dir; 546 base::FilePath origin1_db_dir;
547 FilePath origin2_db_dir; 547 base::FilePath origin2_db_dir;
548 { 548 {
549 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = 549 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
550 new quota::MockSpecialStoragePolicy; 550 new quota::MockSpecialStoragePolicy;
551 special_storage_policy->AddSessionOnly(GURL(kOrigin2Url)); 551 special_storage_policy->AddSessionOnly(GURL(kOrigin2Url));
552 scoped_refptr<DatabaseTracker> tracker( 552 scoped_refptr<DatabaseTracker> tracker(
553 new DatabaseTracker( 553 new DatabaseTracker(
554 temp_dir.path(), false, special_storage_policy, NULL, 554 temp_dir.path(), false, special_storage_policy, NULL,
555 base::MessageLoopProxy::current())); 555 base::MessageLoopProxy::current()));
556 556
557 // Open two new databases. 557 // Open two new databases.
558 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, 558 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
559 &database_size); 559 &database_size);
560 EXPECT_EQ(0, database_size); 560 EXPECT_EQ(0, database_size);
561 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0, 561 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
562 &database_size); 562 &database_size);
563 EXPECT_EQ(0, database_size); 563 EXPECT_EQ(0, database_size);
564 564
565 // Write some data to each file. 565 // Write some data to each file.
566 FilePath db_file; 566 base::FilePath db_file;
567 db_file = tracker->GetFullDBFilePath(kOrigin1, kDB1); 567 db_file = tracker->GetFullDBFilePath(kOrigin1, kDB1);
568 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); 568 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName()));
569 EXPECT_TRUE(EnsureFileOfSize(db_file, 1)); 569 EXPECT_TRUE(EnsureFileOfSize(db_file, 1));
570 570
571 db_file = tracker->GetFullDBFilePath(kOrigin2, kDB2); 571 db_file = tracker->GetFullDBFilePath(kOrigin2, kDB2);
572 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); 572 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName()));
573 EXPECT_TRUE(EnsureFileOfSize(db_file, 2)); 573 EXPECT_TRUE(EnsureFileOfSize(db_file, 2));
574 574
575 // Store the origin database directories as long as they still exist. 575 // Store the origin database directories as long as they still exist.
576 origin1_db_dir = tracker->GetFullDBFilePath(kOrigin1, kDB1).DirName(); 576 origin1_db_dir = tracker->GetFullDBFilePath(kOrigin1, kDB1).DirName();
(...skipping 15 matching lines...) Expand all
592 592
593 // Get all data for all origins. 593 // Get all data for all origins.
594 std::vector<OriginInfo> origins_info; 594 std::vector<OriginInfo> origins_info;
595 EXPECT_TRUE(tracker->GetAllOriginsInfo(&origins_info)); 595 EXPECT_TRUE(tracker->GetAllOriginsInfo(&origins_info));
596 // kOrigin1 was not session-only, so it survived. kOrigin2 was session-only 596 // kOrigin1 was not session-only, so it survived. kOrigin2 was session-only
597 // and it got deleted. 597 // and it got deleted.
598 EXPECT_EQ(size_t(1), origins_info.size()); 598 EXPECT_EQ(size_t(1), origins_info.size());
599 EXPECT_EQ(kOrigin1, origins_info[0].GetOrigin()); 599 EXPECT_EQ(kOrigin1, origins_info[0].GetOrigin());
600 EXPECT_TRUE( 600 EXPECT_TRUE(
601 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin1, kDB1))); 601 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin1, kDB1)));
602 EXPECT_EQ(FilePath(), tracker->GetFullDBFilePath(kOrigin2, kDB2)); 602 EXPECT_EQ(base::FilePath(), tracker->GetFullDBFilePath(kOrigin2, kDB2));
603 603
604 // The origin directory of kOrigin1 remains, but the origin directory of 604 // The origin directory of kOrigin1 remains, but the origin directory of
605 // kOrigin2 is deleted. 605 // kOrigin2 is deleted.
606 EXPECT_TRUE(file_util::PathExists(origin1_db_dir)); 606 EXPECT_TRUE(file_util::PathExists(origin1_db_dir));
607 EXPECT_FALSE(file_util::PathExists(origin2_db_dir)); 607 EXPECT_FALSE(file_util::PathExists(origin2_db_dir));
608 } 608 }
609 609
610 static void DatabaseTrackerSetForceKeepSessionState() { 610 static void DatabaseTrackerSetForceKeepSessionState() {
611 int64 database_size = 0; 611 int64 database_size = 0;
612 const string16 kOrigin1 = 612 const string16 kOrigin1 =
613 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin1Url)); 613 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin1Url));
614 const string16 kOrigin2 = 614 const string16 kOrigin2 =
615 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin2Url)); 615 DatabaseUtil::GetOriginIdentifier(GURL(kOrigin2Url));
616 const string16 kDB1 = ASCIIToUTF16("db1"); 616 const string16 kDB1 = ASCIIToUTF16("db1");
617 const string16 kDB2 = ASCIIToUTF16("db2"); 617 const string16 kDB2 = ASCIIToUTF16("db2");
618 const string16 kDescription = ASCIIToUTF16("database_description"); 618 const string16 kDescription = ASCIIToUTF16("database_description");
619 619
620 // Initialize the tracker database. 620 // Initialize the tracker database.
621 MessageLoop message_loop; 621 MessageLoop message_loop;
622 base::ScopedTempDir temp_dir; 622 base::ScopedTempDir temp_dir;
623 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 623 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
624 FilePath origin1_db_dir; 624 base::FilePath origin1_db_dir;
625 FilePath origin2_db_dir; 625 base::FilePath origin2_db_dir;
626 { 626 {
627 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = 627 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
628 new quota::MockSpecialStoragePolicy; 628 new quota::MockSpecialStoragePolicy;
629 special_storage_policy->AddSessionOnly(GURL(kOrigin2Url)); 629 special_storage_policy->AddSessionOnly(GURL(kOrigin2Url));
630 scoped_refptr<DatabaseTracker> tracker( 630 scoped_refptr<DatabaseTracker> tracker(
631 new DatabaseTracker( 631 new DatabaseTracker(
632 temp_dir.path(), false, special_storage_policy, NULL, 632 temp_dir.path(), false, special_storage_policy, NULL,
633 base::MessageLoopProxy::current())); 633 base::MessageLoopProxy::current()));
634 tracker->SetForceKeepSessionState(); 634 tracker->SetForceKeepSessionState();
635 635
636 // Open two new databases. 636 // Open two new databases.
637 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, 637 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
638 &database_size); 638 &database_size);
639 EXPECT_EQ(0, database_size); 639 EXPECT_EQ(0, database_size);
640 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0, 640 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
641 &database_size); 641 &database_size);
642 EXPECT_EQ(0, database_size); 642 EXPECT_EQ(0, database_size);
643 643
644 // Write some data to each file. 644 // Write some data to each file.
645 FilePath db_file; 645 base::FilePath db_file;
646 db_file = tracker->GetFullDBFilePath(kOrigin1, kDB1); 646 db_file = tracker->GetFullDBFilePath(kOrigin1, kDB1);
647 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); 647 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName()));
648 EXPECT_TRUE(EnsureFileOfSize(db_file, 1)); 648 EXPECT_TRUE(EnsureFileOfSize(db_file, 1));
649 649
650 db_file = tracker->GetFullDBFilePath(kOrigin2, kDB2); 650 db_file = tracker->GetFullDBFilePath(kOrigin2, kDB2);
651 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName())); 651 EXPECT_TRUE(file_util::CreateDirectory(db_file.DirName()));
652 EXPECT_TRUE(EnsureFileOfSize(db_file, 2)); 652 EXPECT_TRUE(EnsureFileOfSize(db_file, 2));
653 653
654 // Store the origin database directories as long as they still exist. 654 // Store the origin database directories as long as they still exist.
655 origin1_db_dir = tracker->GetFullDBFilePath(kOrigin1, kDB1).DirName(); 655 origin1_db_dir = tracker->GetFullDBFilePath(kOrigin1, kDB1).DirName();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT); 752 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT);
753 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName)); 753 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName));
754 EXPECT_FALSE(observer.DidReceiveNewNotification()); 754 EXPECT_FALSE(observer.DidReceiveNewNotification());
755 755
756 // -------------------------------------------------------- 756 // --------------------------------------------------------
757 // Create a record of a database in the tracker db and create 757 // Create a record of a database in the tracker db and create
758 // a spoof_db_file on disk in the expected location. 758 // a spoof_db_file on disk in the expected location.
759 int64 database_size = 0; 759 int64 database_size = 0;
760 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0, 760 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0,
761 &database_size); 761 &database_size);
762 FilePath spoof_db_file = tracker->GetFullDBFilePath(kOriginId, kName); 762 base::FilePath spoof_db_file = tracker->GetFullDBFilePath(kOriginId, kName);
763 EXPECT_FALSE(tracker->GetFullDBFilePath(kOriginId, kName).empty()); 763 EXPECT_FALSE(tracker->GetFullDBFilePath(kOriginId, kName).empty());
764 EXPECT_TRUE(file_util::CreateDirectory(spoof_db_file.DirName())); 764 EXPECT_TRUE(file_util::CreateDirectory(spoof_db_file.DirName()));
765 EXPECT_TRUE(EnsureFileOfSize(spoof_db_file, 1)); 765 EXPECT_TRUE(EnsureFileOfSize(spoof_db_file, 1));
766 766
767 // Verify does no harm with a non-error is reported. 767 // Verify does no harm with a non-error is reported.
768 tracker->HandleSqliteError(kOriginId, kName, SQLITE_OK); 768 tracker->HandleSqliteError(kOriginId, kName, SQLITE_OK);
769 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName)); 769 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName));
770 EXPECT_FALSE(observer.DidReceiveNewNotification()); 770 EXPECT_FALSE(observer.DidReceiveNewNotification());
771 771
772 // Verify that with a connection open, the db is scheduled for deletion, 772 // Verify that with a connection open, the db is scheduled for deletion,
773 // but that the file still exists. 773 // but that the file still exists.
774 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT); 774 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT);
775 EXPECT_TRUE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName)); 775 EXPECT_TRUE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName));
776 EXPECT_TRUE(observer.DidReceiveNewNotification()); 776 EXPECT_TRUE(observer.DidReceiveNewNotification());
777 EXPECT_TRUE(file_util::PathExists(spoof_db_file)); 777 EXPECT_TRUE(file_util::PathExists(spoof_db_file));
778 778
779 // Verify that once closed, the file is deleted and the record in the 779 // Verify that once closed, the file is deleted and the record in the
780 // tracker db is removed. 780 // tracker db is removed.
781 tracker->DatabaseClosed(kOriginId, kName); 781 tracker->DatabaseClosed(kOriginId, kName);
782 EXPECT_FALSE(file_util::PathExists(spoof_db_file)); 782 EXPECT_FALSE(file_util::PathExists(spoof_db_file));
783 EXPECT_TRUE(tracker->GetFullDBFilePath(kOriginId, kName).empty()); 783 EXPECT_TRUE(tracker->GetFullDBFilePath(kOriginId, kName).empty());
784 784
785 // -------------------------------------------------------- 785 // --------------------------------------------------------
786 // Create another record of a database in the tracker db and create 786 // Create another record of a database in the tracker db and create
787 // a spoof_db_file on disk in the expected location. 787 // a spoof_db_file on disk in the expected location.
788 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0, 788 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0,
789 &database_size); 789 &database_size);
790 FilePath spoof_db_file2 = tracker->GetFullDBFilePath(kOriginId, kName); 790 base::FilePath spoof_db_file2 = tracker->GetFullDBFilePath(kOriginId, kName) ;
791 EXPECT_FALSE(tracker->GetFullDBFilePath(kOriginId, kName).empty()); 791 EXPECT_FALSE(tracker->GetFullDBFilePath(kOriginId, kName).empty());
792 EXPECT_NE(spoof_db_file, spoof_db_file2); 792 EXPECT_NE(spoof_db_file, spoof_db_file2);
793 EXPECT_TRUE(file_util::CreateDirectory(spoof_db_file2.DirName())); 793 EXPECT_TRUE(file_util::CreateDirectory(spoof_db_file2.DirName()));
794 EXPECT_TRUE(EnsureFileOfSize(spoof_db_file2, 1)); 794 EXPECT_TRUE(EnsureFileOfSize(spoof_db_file2, 1));
795 795
796 // Verify that with no connection open, the db is deleted immediately. 796 // Verify that with no connection open, the db is deleted immediately.
797 tracker->DatabaseClosed(kOriginId, kName); 797 tracker->DatabaseClosed(kOriginId, kName);
798 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT); 798 tracker->HandleSqliteError(kOriginId, kName, SQLITE_CORRUPT);
799 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName)); 799 EXPECT_FALSE(tracker->IsDatabaseScheduledForDeletion(kOriginId, kName));
800 EXPECT_FALSE(observer.DidReceiveNewNotification()); 800 EXPECT_FALSE(observer.DidReceiveNewNotification());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 839
840 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) { 840 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) {
841 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid(); 841 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid();
842 } 842 }
843 843
844 TEST(DatabaseTrackerTest, HandleSqliteError) { 844 TEST(DatabaseTrackerTest, HandleSqliteError) {
845 DatabaseTracker_TestHelper_Test::HandleSqliteError(); 845 DatabaseTracker_TestHelper_Test::HandleSqliteError();
846 } 846 }
847 847
848 } // namespace webkit_database 848 } // namespace webkit_database
OLDNEW
« no previous file with comments | « webkit/database/database_tracker.cc ('k') | webkit/database/database_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698