| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // We declare a helper class, and make it a friend of DatabaseTracker using | 75 // We declare a helper class, and make it a friend of DatabaseTracker using |
| 76 // the FRIEND_TEST() macro, and we implement all tests we want to run as | 76 // the FRIEND_TEST() macro, and we implement all tests we want to run as |
| 77 // static methods of this class. Then we make our TEST() targets call these | 77 // static methods of this class. Then we make our TEST() targets call these |
| 78 // static functions. This allows us to run each test in normal mode and | 78 // static functions. This allows us to run each test in normal mode and |
| 79 // incognito mode without writing the same code twice. | 79 // incognito mode without writing the same code twice. |
| 80 class DatabaseTracker_TestHelper_Test { | 80 class DatabaseTracker_TestHelper_Test { |
| 81 public: | 81 public: |
| 82 static void TestDeleteOpenDatabase(bool incognito_mode) { | 82 static void TestDeleteOpenDatabase(bool incognito_mode) { |
| 83 // Initialize the tracker database. | 83 // Initialize the tracker database. |
| 84 ScopedTempDir temp_dir; | 84 ScopedTempDir temp_dir; |
| 85 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); | 85 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 86 scoped_refptr<DatabaseTracker> tracker( | 86 scoped_refptr<DatabaseTracker> tracker( |
| 87 new DatabaseTracker(temp_dir.path(), incognito_mode)); | 87 new DatabaseTracker(temp_dir.path(), incognito_mode)); |
| 88 | 88 |
| 89 // Create and open three databases. | 89 // Create and open three databases. |
| 90 int64 database_size = 0; | 90 int64 database_size = 0; |
| 91 int64 space_available = 0; | 91 int64 space_available = 0; |
| 92 const string16 kOrigin1 = ASCIIToUTF16("origin1"); | 92 const string16 kOrigin1 = ASCIIToUTF16("origin1"); |
| 93 const string16 kOrigin2 = ASCIIToUTF16("origin2"); | 93 const string16 kOrigin2 = ASCIIToUTF16("origin2"); |
| 94 const string16 kDB1 = ASCIIToUTF16("db1"); | 94 const string16 kDB1 = ASCIIToUTF16("db1"); |
| 95 const string16 kDB2 = ASCIIToUTF16("db2"); | 95 const string16 kDB2 = ASCIIToUTF16("db2"); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 EXPECT_TRUE( | 174 EXPECT_TRUE( |
| 175 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB3))); | 175 file_util::PathExists(tracker->GetFullDBFilePath(kOrigin2, kDB3))); |
| 176 | 176 |
| 177 tracker->DatabaseClosed(kOrigin2, kDB3); | 177 tracker->DatabaseClosed(kOrigin2, kDB3); |
| 178 tracker->RemoveObserver(&observer); | 178 tracker->RemoveObserver(&observer); |
| 179 } | 179 } |
| 180 | 180 |
| 181 static void TestDatabaseTracker(bool incognito_mode) { | 181 static void TestDatabaseTracker(bool incognito_mode) { |
| 182 // Initialize the tracker database. | 182 // Initialize the tracker database. |
| 183 ScopedTempDir temp_dir; | 183 ScopedTempDir temp_dir; |
| 184 EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); | 184 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 185 scoped_refptr<DatabaseTracker> tracker( | 185 scoped_refptr<DatabaseTracker> tracker( |
| 186 new DatabaseTracker(temp_dir.path(), incognito_mode)); | 186 new DatabaseTracker(temp_dir.path(), incognito_mode)); |
| 187 | 187 |
| 188 // Add two observers. | 188 // Add two observers. |
| 189 TestObserver observer1; | 189 TestObserver observer1; |
| 190 TestObserver observer2; | 190 TestObserver observer2; |
| 191 tracker->AddObserver(&observer1); | 191 tracker->AddObserver(&observer1); |
| 192 tracker->AddObserver(&observer2); | 192 tracker->AddObserver(&observer2); |
| 193 | 193 |
| 194 // Open three new databases. | 194 // Open three new databases. |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 | 388 |
| 389 TEST(DatabaseTrackerTest, DatabaseTracker) { | 389 TEST(DatabaseTrackerTest, DatabaseTracker) { |
| 390 DatabaseTracker_TestHelper_Test::TestDatabaseTracker(false); | 390 DatabaseTracker_TestHelper_Test::TestDatabaseTracker(false); |
| 391 } | 391 } |
| 392 | 392 |
| 393 TEST(DatabaseTrackerTest, DatabaseTrackerIncognitoMode) { | 393 TEST(DatabaseTrackerTest, DatabaseTrackerIncognitoMode) { |
| 394 DatabaseTracker_TestHelper_Test::TestDatabaseTracker(true); | 394 DatabaseTracker_TestHelper_Test::TestDatabaseTracker(true); |
| 395 } | 395 } |
| 396 | 396 |
| 397 } // namespace webkit_database | 397 } // namespace webkit_database |
| OLD | NEW |