| 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_path.h" | 7 #include "base/files/file_path.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 11 #include "base/platform_file.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/sqlite/sqlite3.h" | 17 #include "third_party/sqlite/sqlite3.h" |
| 18 #include "webkit/browser/database/database_tracker.h" | 18 #include "webkit/browser/database/database_tracker.h" |
| 19 #include "webkit/browser/quota/mock_special_storage_policy.h" | 19 #include "webkit/browser/quota/mock_special_storage_policy.h" |
| 20 #include "webkit/browser/quota/quota_manager_proxy.h" | 20 #include "webkit/browser/quota/quota_manager_proxy.h" |
| 21 #include "webkit/common/database/database_identifier.h" | 21 #include "webkit/common/database/database_identifier.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 std::map<GURL, std::pair<int, int64> > modifications_; | 166 std::map<GURL, std::pair<int, int64> > modifications_; |
| 167 | 167 |
| 168 protected: | 168 protected: |
| 169 virtual ~TestQuotaManagerProxy() { | 169 virtual ~TestQuotaManagerProxy() { |
| 170 EXPECT_FALSE(registered_client_); | 170 EXPECT_FALSE(registered_client_); |
| 171 } | 171 } |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 | 174 |
| 175 bool EnsureFileOfSize(const base::FilePath& file_path, int64 length) { | 175 bool EnsureFileOfSize(const base::FilePath& file_path, int64 length) { |
| 176 base::PlatformFileError error_code(base::PLATFORM_FILE_ERROR_FAILED); | 176 base::File file(file_path, |
| 177 base::PlatformFile file = | 177 base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE); |
| 178 base::CreatePlatformFile( | 178 if (!file.IsValid()) |
| 179 file_path, | |
| 180 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE, | |
| 181 NULL, | |
| 182 &error_code); | |
| 183 if (error_code != base::PLATFORM_FILE_OK) | |
| 184 return false; | 179 return false; |
| 185 if (!base::TruncatePlatformFile(file, length)) | 180 return file.SetLength(length); |
| 186 error_code = base::PLATFORM_FILE_ERROR_FAILED; | |
| 187 base::ClosePlatformFile(file); | |
| 188 return error_code == base::PLATFORM_FILE_OK; | |
| 189 } | 181 } |
| 190 | 182 |
| 191 } // namespace | 183 } // namespace |
| 192 | 184 |
| 193 namespace webkit_database { | 185 namespace webkit_database { |
| 194 | 186 |
| 195 // We declare a helper class, and make it a friend of DatabaseTracker using | 187 // We declare a helper class, and make it a friend of DatabaseTracker using |
| 196 // the FRIEND_TEST() macro, and we implement all tests we want to run as | 188 // the FRIEND_TEST() macro, and we implement all tests we want to run as |
| 197 // static methods of this class. Then we make our TEST() targets call these | 189 // static methods of this class. Then we make our TEST() targets call these |
| 198 // static functions. This allows us to run each test in normal mode and | 190 // static functions. This allows us to run each test in normal mode and |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 | 862 |
| 871 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) { | 863 TEST(DatabaseTrackerTest, EmptyDatabaseNameIsValid) { |
| 872 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid(); | 864 DatabaseTracker_TestHelper_Test::EmptyDatabaseNameIsValid(); |
| 873 } | 865 } |
| 874 | 866 |
| 875 TEST(DatabaseTrackerTest, HandleSqliteError) { | 867 TEST(DatabaseTrackerTest, HandleSqliteError) { |
| 876 DatabaseTracker_TestHelper_Test::HandleSqliteError(); | 868 DatabaseTracker_TestHelper_Test::HandleSqliteError(); |
| 877 } | 869 } |
| 878 | 870 |
| 879 } // namespace webkit_database | 871 } // namespace webkit_database |
| OLD | NEW |