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

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

Issue 16155009: Update webkit/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 class DatabaseTracker_TestHelper_Test { 189 class DatabaseTracker_TestHelper_Test {
190 public: 190 public:
191 static void TestDeleteOpenDatabase(bool incognito_mode) { 191 static void TestDeleteOpenDatabase(bool incognito_mode) {
192 // Initialize the tracker database. 192 // Initialize the tracker database.
193 base::ScopedTempDir temp_dir; 193 base::ScopedTempDir temp_dir;
194 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 194 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
195 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = 195 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
196 new quota::MockSpecialStoragePolicy; 196 new quota::MockSpecialStoragePolicy;
197 special_storage_policy->AddProtected(GURL(kOrigin2Url)); 197 special_storage_policy->AddProtected(GURL(kOrigin2Url));
198 scoped_refptr<DatabaseTracker> tracker( 198 scoped_refptr<DatabaseTracker> tracker(
199 new DatabaseTracker(temp_dir.path(), incognito_mode, 199 new DatabaseTracker(temp_dir.path(),
200 special_storage_policy, NULL, NULL)); 200 incognito_mode,
201 special_storage_policy.get(),
202 NULL,
203 NULL));
201 204
202 // Create and open three databases. 205 // Create and open three databases.
203 int64 database_size = 0; 206 int64 database_size = 0;
204 const base::string16 kOrigin1 = 207 const base::string16 kOrigin1 =
205 webkit_base::GetOriginIdentifierFromURL(GURL(kOrigin1Url)); 208 webkit_base::GetOriginIdentifierFromURL(GURL(kOrigin1Url));
206 const base::string16 kOrigin2 = 209 const base::string16 kOrigin2 =
207 webkit_base::GetOriginIdentifierFromURL(GURL(kOrigin2Url)); 210 webkit_base::GetOriginIdentifierFromURL(GURL(kOrigin2Url));
208 const base::string16 kDB1 = ASCIIToUTF16("db1"); 211 const base::string16 kDB1 = ASCIIToUTF16("db1");
209 const base::string16 kDB2 = ASCIIToUTF16("db2"); 212 const base::string16 kDB2 = ASCIIToUTF16("db2");
210 const base::string16 kDB3 = ASCIIToUTF16("db3"); 213 const base::string16 kDB3 = ASCIIToUTF16("db3");
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 297 }
295 298
296 static void TestDatabaseTracker(bool incognito_mode) { 299 static void TestDatabaseTracker(bool incognito_mode) {
297 // Initialize the tracker database. 300 // Initialize the tracker database.
298 base::ScopedTempDir temp_dir; 301 base::ScopedTempDir temp_dir;
299 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 302 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
300 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = 303 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
301 new quota::MockSpecialStoragePolicy; 304 new quota::MockSpecialStoragePolicy;
302 special_storage_policy->AddProtected(GURL(kOrigin2Url)); 305 special_storage_policy->AddProtected(GURL(kOrigin2Url));
303 scoped_refptr<DatabaseTracker> tracker( 306 scoped_refptr<DatabaseTracker> tracker(
304 new DatabaseTracker(temp_dir.path(), incognito_mode, 307 new DatabaseTracker(temp_dir.path(),
305 special_storage_policy, NULL, NULL)); 308 incognito_mode,
309 special_storage_policy.get(),
310 NULL,
311 NULL));
306 312
307 // Add two observers. 313 // Add two observers.
308 TestObserver observer1; 314 TestObserver observer1;
309 TestObserver observer2; 315 TestObserver observer2;
310 tracker->AddObserver(&observer1); 316 tracker->AddObserver(&observer1);
311 tracker->AddObserver(&observer2); 317 tracker->AddObserver(&observer2);
312 318
313 // Open three new databases. 319 // Open three new databases.
314 int64 database_size = 0; 320 int64 database_size = 0;
315 const base::string16 kOrigin1 = 321 const base::string16 kOrigin1 =
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 const base::string16 kName = ASCIIToUTF16("name"); 451 const base::string16 kName = ASCIIToUTF16("name");
446 const base::string16 kDescription = ASCIIToUTF16("description"); 452 const base::string16 kDescription = ASCIIToUTF16("description");
447 453
448 base::ScopedTempDir temp_dir; 454 base::ScopedTempDir temp_dir;
449 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 455 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
450 456
451 // Initialize the tracker with a QuotaManagerProxy 457 // Initialize the tracker with a QuotaManagerProxy
452 scoped_refptr<TestQuotaManagerProxy> test_quota_proxy( 458 scoped_refptr<TestQuotaManagerProxy> test_quota_proxy(
453 new TestQuotaManagerProxy); 459 new TestQuotaManagerProxy);
454 scoped_refptr<DatabaseTracker> tracker( 460 scoped_refptr<DatabaseTracker> tracker(
455 new DatabaseTracker(temp_dir.path(), false /* incognito */, 461 new DatabaseTracker(temp_dir.path(),
456 NULL, test_quota_proxy, NULL)); 462 false /* incognito */,
463 NULL,
464 test_quota_proxy.get(),
465 NULL));
457 EXPECT_TRUE(test_quota_proxy->registered_client_); 466 EXPECT_TRUE(test_quota_proxy->registered_client_);
458 467
459 // Create a database and modify it a couple of times, close it, 468 // Create a database and modify it a couple of times, close it,
460 // then delete it. Observe the tracker notifies accordingly. 469 // then delete it. Observe the tracker notifies accordingly.
461 470
462 int64 database_size = 0; 471 int64 database_size = 0;
463 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0, 472 tracker->DatabaseOpened(kOriginId, kName, kDescription, 0,
464 &database_size); 473 &database_size);
465 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin)); 474 EXPECT_TRUE(test_quota_proxy->WasAccessNotified(kOrigin));
466 test_quota_proxy->reset(); 475 test_quota_proxy->reset();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 base::MessageLoop message_loop; 556 base::MessageLoop message_loop;
548 base::ScopedTempDir temp_dir; 557 base::ScopedTempDir temp_dir;
549 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 558 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
550 base::FilePath origin1_db_dir; 559 base::FilePath origin1_db_dir;
551 base::FilePath origin2_db_dir; 560 base::FilePath origin2_db_dir;
552 { 561 {
553 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = 562 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
554 new quota::MockSpecialStoragePolicy; 563 new quota::MockSpecialStoragePolicy;
555 special_storage_policy->AddSessionOnly(GURL(kOrigin2Url)); 564 special_storage_policy->AddSessionOnly(GURL(kOrigin2Url));
556 scoped_refptr<DatabaseTracker> tracker( 565 scoped_refptr<DatabaseTracker> tracker(
557 new DatabaseTracker( 566 new DatabaseTracker(temp_dir.path(),
558 temp_dir.path(), false, special_storage_policy, NULL, 567 false,
559 base::MessageLoopProxy::current())); 568 special_storage_policy.get(),
569 NULL,
570 base::MessageLoopProxy::current()));
560 571
561 // Open two new databases. 572 // Open two new databases.
562 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, 573 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
563 &database_size); 574 &database_size);
564 EXPECT_EQ(0, database_size); 575 EXPECT_EQ(0, database_size);
565 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0, 576 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
566 &database_size); 577 &database_size);
567 EXPECT_EQ(0, database_size); 578 EXPECT_EQ(0, database_size);
568 579
569 // Write some data to each file. 580 // Write some data to each file.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 base::MessageLoop message_loop; 636 base::MessageLoop message_loop;
626 base::ScopedTempDir temp_dir; 637 base::ScopedTempDir temp_dir;
627 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 638 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
628 base::FilePath origin1_db_dir; 639 base::FilePath origin1_db_dir;
629 base::FilePath origin2_db_dir; 640 base::FilePath origin2_db_dir;
630 { 641 {
631 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy = 642 scoped_refptr<quota::MockSpecialStoragePolicy> special_storage_policy =
632 new quota::MockSpecialStoragePolicy; 643 new quota::MockSpecialStoragePolicy;
633 special_storage_policy->AddSessionOnly(GURL(kOrigin2Url)); 644 special_storage_policy->AddSessionOnly(GURL(kOrigin2Url));
634 scoped_refptr<DatabaseTracker> tracker( 645 scoped_refptr<DatabaseTracker> tracker(
635 new DatabaseTracker( 646 new DatabaseTracker(temp_dir.path(),
636 temp_dir.path(), false, special_storage_policy, NULL, 647 false,
637 base::MessageLoopProxy::current())); 648 special_storage_policy.get(),
649 NULL,
650 base::MessageLoopProxy::current()));
638 tracker->SetForceKeepSessionState(); 651 tracker->SetForceKeepSessionState();
639 652
640 // Open two new databases. 653 // Open two new databases.
641 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0, 654 tracker->DatabaseOpened(kOrigin1, kDB1, kDescription, 0,
642 &database_size); 655 &database_size);
643 EXPECT_EQ(0, database_size); 656 EXPECT_EQ(0, database_size);
644 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0, 657 tracker->DatabaseOpened(kOrigin2, kDB2, kDescription, 0,
645 &database_size); 658 &database_size);
646 EXPECT_EQ(0, database_size); 659 EXPECT_EQ(0, database_size);
647 660
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 859
847 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) { 860 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) {
848 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid(); 861 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid();
849 } 862 }
850 863
851 TEST(DatabaseTrackerTest, HandleSqliteError) { 864 TEST(DatabaseTrackerTest, HandleSqliteError) {
852 DatabaseTracker_TestHelper_Test::HandleSqliteError(); 865 DatabaseTracker_TestHelper_Test::HandleSqliteError();
853 } 866 }
854 867
855 } // namespace webkit_database 868 } // namespace webkit_database
OLDNEW
« no previous file with comments | « webkit/browser/database/database_tracker.cc ('k') | webkit/browser/fileapi/copy_or_move_file_validator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698