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

Side by Side Diff: webkit/appcache/appcache_database_unittest.cc

Issue 11111021: Remove ref counting on sql::ErrorDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes as requested Created 8 years, 2 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 | « sql/statement_unittest.cc ('k') | webkit/database/databases_table_unittest.cc » ('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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/scoped_temp_dir.h" 8 #include "base/scoped_temp_dir.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "sql/connection.h" 10 #include "sql/connection.h"
11 #include "sql/meta_table.h" 11 #include "sql/meta_table.h"
12 #include "sql/statement.h" 12 #include "sql/statement.h"
13 #include "sql/transaction.h" 13 #include "sql/transaction.h"
14 #include "webkit/appcache/appcache_database.h" 14 #include "webkit/appcache/appcache_database.h"
15 #include "webkit/appcache/appcache_entry.h" 15 #include "webkit/appcache/appcache_entry.h"
16 16
17 namespace { 17 namespace {
18 18
19 const base::Time kZeroTime; 19 const base::Time kZeroTime;
20 20
21 class TestErrorDelegate : public sql::ErrorDelegate { 21 class TestErrorDelegate : public sql::ErrorDelegate {
22 public: 22 public:
23 TestErrorDelegate() {}
24 virtual ~TestErrorDelegate() {}
25
23 virtual int OnError(int error, 26 virtual int OnError(int error,
24 sql::Connection* connection, 27 sql::Connection* connection,
25 sql::Statement* stmt) OVERRIDE { 28 sql::Statement* stmt) OVERRIDE {
26 return error; 29 return error;
27 } 30 }
28 31
29 private: 32 private:
30 virtual ~TestErrorDelegate() {} 33 DISALLOW_COPY_AND_ASSIGN(TestErrorDelegate);
31 }; 34 };
32 35
33 } // namespace 36 } // namespace
34 37
35 namespace appcache { 38 namespace appcache {
36 39
37 class AppCacheDatabaseTest {}; 40 class AppCacheDatabaseTest {};
38 41
39 TEST(AppCacheDatabaseTest, LazyOpen) { 42 TEST(AppCacheDatabaseTest, LazyOpen) {
40 // Use an empty file path to use an in-memory sqlite database. 43 // Use an empty file path to use an in-memory sqlite database.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 EXPECT_FALSE(file_util::DirectoryExists(kNestedDir)); 85 EXPECT_FALSE(file_util::DirectoryExists(kNestedDir));
83 EXPECT_FALSE(file_util::PathExists(kOtherFile)); 86 EXPECT_FALSE(file_util::PathExists(kOtherFile));
84 } 87 }
85 88
86 TEST(AppCacheDatabaseTest, EntryRecords) { 89 TEST(AppCacheDatabaseTest, EntryRecords) {
87 const FilePath kEmptyPath; 90 const FilePath kEmptyPath;
88 AppCacheDatabase db(kEmptyPath); 91 AppCacheDatabase db(kEmptyPath);
89 EXPECT_TRUE(db.LazyOpen(true)); 92 EXPECT_TRUE(db.LazyOpen(true));
90 93
91 // Set an error delegate that will make all operations return false on error. 94 // Set an error delegate that will make all operations return false on error.
92 scoped_refptr<TestErrorDelegate> error_delegate(new TestErrorDelegate); 95 db.db_->set_error_delegate(new TestErrorDelegate());
93 db.db_->set_error_delegate(error_delegate);
94 96
95 AppCacheDatabase::EntryRecord entry; 97 AppCacheDatabase::EntryRecord entry;
96 98
97 entry.cache_id = 1; 99 entry.cache_id = 1;
98 entry.url = GURL("http://blah/1"); 100 entry.url = GURL("http://blah/1");
99 entry.flags = AppCacheEntry::MASTER; 101 entry.flags = AppCacheEntry::MASTER;
100 entry.response_id = 1; 102 entry.response_id = 1;
101 entry.response_size = 100; 103 entry.response_size = 100;
102 EXPECT_TRUE(db.InsertEntry(&entry)); 104 EXPECT_TRUE(db.InsertEntry(&entry));
103 EXPECT_FALSE(db.InsertEntry(&entry)); 105 EXPECT_FALSE(db.InsertEntry(&entry));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 EXPECT_TRUE(db.DeleteEntriesForCache(1)); 158 EXPECT_TRUE(db.DeleteEntriesForCache(1));
157 EXPECT_FALSE(db.AddEntryFlags(GURL("http://blah/1"), 1, 159 EXPECT_FALSE(db.AddEntryFlags(GURL("http://blah/1"), 1,
158 AppCacheEntry::FOREIGN)); 160 AppCacheEntry::FOREIGN));
159 } 161 }
160 162
161 TEST(AppCacheDatabaseTest, CacheRecords) { 163 TEST(AppCacheDatabaseTest, CacheRecords) {
162 const FilePath kEmptyPath; 164 const FilePath kEmptyPath;
163 AppCacheDatabase db(kEmptyPath); 165 AppCacheDatabase db(kEmptyPath);
164 EXPECT_TRUE(db.LazyOpen(true)); 166 EXPECT_TRUE(db.LazyOpen(true));
165 167
166 scoped_refptr<TestErrorDelegate> error_delegate(new TestErrorDelegate); 168 db.db_->set_error_delegate(new TestErrorDelegate());
167 db.db_->set_error_delegate(error_delegate);
168 169
169 const AppCacheDatabase::CacheRecord kZeroRecord; 170 const AppCacheDatabase::CacheRecord kZeroRecord;
170 AppCacheDatabase::CacheRecord record; 171 AppCacheDatabase::CacheRecord record;
171 EXPECT_FALSE(db.FindCache(1, &record)); 172 EXPECT_FALSE(db.FindCache(1, &record));
172 173
173 record.cache_id = 1; 174 record.cache_id = 1;
174 record.group_id = 1; 175 record.group_id = 1;
175 record.online_wildcard = true; 176 record.online_wildcard = true;
176 record.update_time = kZeroTime; 177 record.update_time = kZeroTime;
177 record.cache_size = 100; 178 record.cache_size = 100;
(...skipping 21 matching lines...) Expand all
199 EXPECT_FALSE(db.FindCacheForGroup(1, &record)); 200 EXPECT_FALSE(db.FindCacheForGroup(1, &record));
200 201
201 EXPECT_TRUE(db.DeleteCache(1)); 202 EXPECT_TRUE(db.DeleteCache(1));
202 } 203 }
203 204
204 TEST(AppCacheDatabaseTest, GroupRecords) { 205 TEST(AppCacheDatabaseTest, GroupRecords) {
205 const FilePath kEmptyPath; 206 const FilePath kEmptyPath;
206 AppCacheDatabase db(kEmptyPath); 207 AppCacheDatabase db(kEmptyPath);
207 EXPECT_TRUE(db.LazyOpen(true)); 208 EXPECT_TRUE(db.LazyOpen(true));
208 209
209 scoped_refptr<TestErrorDelegate> error_delegate(new TestErrorDelegate); 210 db.db_->set_error_delegate(new TestErrorDelegate());
210 db.db_->set_error_delegate(error_delegate);
211 211
212 const GURL kManifestUrl("http://blah/manifest"); 212 const GURL kManifestUrl("http://blah/manifest");
213 const GURL kOrigin(kManifestUrl.GetOrigin()); 213 const GURL kOrigin(kManifestUrl.GetOrigin());
214 const base::Time kLastAccessTime = base::Time::Now(); 214 const base::Time kLastAccessTime = base::Time::Now();
215 const base::Time kCreationTime = 215 const base::Time kCreationTime =
216 kLastAccessTime - base::TimeDelta::FromDays(7); 216 kLastAccessTime - base::TimeDelta::FromDays(7);
217 217
218 const AppCacheDatabase::GroupRecord kZeroRecord; 218 const AppCacheDatabase::GroupRecord kZeroRecord;
219 AppCacheDatabase::GroupRecord record; 219 AppCacheDatabase::GroupRecord record;
220 std::vector<AppCacheDatabase::GroupRecord> records; 220 std::vector<AppCacheDatabase::GroupRecord> records;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 EXPECT_EQ(1, record.group_id); 327 EXPECT_EQ(1, record.group_id);
328 EXPECT_EQ(kManifest2, record.manifest_url); 328 EXPECT_EQ(kManifest2, record.manifest_url);
329 EXPECT_EQ(kOrigin2, record.origin); 329 EXPECT_EQ(kOrigin2, record.origin);
330 } 330 }
331 331
332 TEST(AppCacheDatabaseTest, NamespaceRecords) { 332 TEST(AppCacheDatabaseTest, NamespaceRecords) {
333 const FilePath kEmptyPath; 333 const FilePath kEmptyPath;
334 AppCacheDatabase db(kEmptyPath); 334 AppCacheDatabase db(kEmptyPath);
335 EXPECT_TRUE(db.LazyOpen(true)); 335 EXPECT_TRUE(db.LazyOpen(true));
336 336
337 scoped_refptr<TestErrorDelegate> error_delegate(new TestErrorDelegate); 337 db.db_->set_error_delegate(new TestErrorDelegate());
338 db.db_->set_error_delegate(error_delegate);
339 338
340 const GURL kFooNameSpace1("http://foo/namespace1"); 339 const GURL kFooNameSpace1("http://foo/namespace1");
341 const GURL kFooNameSpace2("http://foo/namespace2"); 340 const GURL kFooNameSpace2("http://foo/namespace2");
342 const GURL kFooFallbackEntry("http://foo/entry"); 341 const GURL kFooFallbackEntry("http://foo/entry");
343 const GURL kFooOrigin(kFooNameSpace1.GetOrigin()); 342 const GURL kFooOrigin(kFooNameSpace1.GetOrigin());
344 const GURL kBarNameSpace1("http://bar/namespace1"); 343 const GURL kBarNameSpace1("http://bar/namespace1");
345 const GURL kBarNameSpace2("http://bar/namespace2"); 344 const GURL kBarNameSpace2("http://bar/namespace2");
346 const GURL kBarFallbackEntry("http://bar/entry"); 345 const GURL kBarFallbackEntry("http://bar/entry");
347 const GURL kBarOrigin(kBarNameSpace1.GetOrigin()); 346 const GURL kBarOrigin(kBarNameSpace1.GetOrigin());
348 347
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 fallbacks.clear(); 427 fallbacks.clear();
429 EXPECT_TRUE(db.FindNamespacesForOrigin(kBarOrigin, &intercepts, &fallbacks)); 428 EXPECT_TRUE(db.FindNamespacesForOrigin(kBarOrigin, &intercepts, &fallbacks));
430 EXPECT_EQ(2U, fallbacks.size()); 429 EXPECT_EQ(2U, fallbacks.size());
431 } 430 }
432 431
433 TEST(AppCacheDatabaseTest, OnlineWhiteListRecords) { 432 TEST(AppCacheDatabaseTest, OnlineWhiteListRecords) {
434 const FilePath kEmptyPath; 433 const FilePath kEmptyPath;
435 AppCacheDatabase db(kEmptyPath); 434 AppCacheDatabase db(kEmptyPath);
436 EXPECT_TRUE(db.LazyOpen(true)); 435 EXPECT_TRUE(db.LazyOpen(true));
437 436
438 scoped_refptr<TestErrorDelegate> error_delegate(new TestErrorDelegate); 437 db.db_->set_error_delegate(new TestErrorDelegate());
439 db.db_->set_error_delegate(error_delegate);
440 438
441 const GURL kFooNameSpace1("http://foo/namespace1"); 439 const GURL kFooNameSpace1("http://foo/namespace1");
442 const GURL kFooNameSpace2("http://foo/namespace2"); 440 const GURL kFooNameSpace2("http://foo/namespace2");
443 const GURL kBarNameSpace1("http://bar/namespace1"); 441 const GURL kBarNameSpace1("http://bar/namespace1");
444 442
445 const AppCacheDatabase::OnlineWhiteListRecord kZeroRecord; 443 const AppCacheDatabase::OnlineWhiteListRecord kZeroRecord;
446 AppCacheDatabase::OnlineWhiteListRecord record; 444 AppCacheDatabase::OnlineWhiteListRecord record;
447 std::vector<AppCacheDatabase::OnlineWhiteListRecord> records; 445 std::vector<AppCacheDatabase::OnlineWhiteListRecord> records;
448 446
449 // Behavior with an empty table 447 // Behavior with an empty table
(...skipping 25 matching lines...) Expand all
475 records.clear(); 473 records.clear();
476 EXPECT_TRUE(db.FindOnlineWhiteListForCache(1, &records)); 474 EXPECT_TRUE(db.FindOnlineWhiteListForCache(1, &records));
477 EXPECT_TRUE(records.empty()); 475 EXPECT_TRUE(records.empty());
478 } 476 }
479 477
480 TEST(AppCacheDatabaseTest, DeletableResponseIds) { 478 TEST(AppCacheDatabaseTest, DeletableResponseIds) {
481 const FilePath kEmptyPath; 479 const FilePath kEmptyPath;
482 AppCacheDatabase db(kEmptyPath); 480 AppCacheDatabase db(kEmptyPath);
483 EXPECT_TRUE(db.LazyOpen(true)); 481 EXPECT_TRUE(db.LazyOpen(true));
484 482
485 scoped_refptr<TestErrorDelegate> error_delegate(new TestErrorDelegate); 483 db.db_->set_error_delegate(new TestErrorDelegate());
486 db.db_->set_error_delegate(error_delegate);
487 484
488 std::vector<int64> ids; 485 std::vector<int64> ids;
489 486
490 EXPECT_TRUE(db.GetDeletableResponseIds(&ids, kint64max, 100)); 487 EXPECT_TRUE(db.GetDeletableResponseIds(&ids, kint64max, 100));
491 EXPECT_TRUE(ids.empty()); 488 EXPECT_TRUE(ids.empty());
492 ids.push_back(0); 489 ids.push_back(0);
493 EXPECT_TRUE(db.DeleteDeletableResponseIds(ids)); 490 EXPECT_TRUE(db.DeleteDeletableResponseIds(ids));
494 EXPECT_TRUE(db.InsertDeletableResponseIds(ids)); 491 EXPECT_TRUE(db.InsertDeletableResponseIds(ids));
495 492
496 ids.clear(); 493 ids.clear();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 const GURL kManifestUrl("http://blah/manifest"); 549 const GURL kManifestUrl("http://blah/manifest");
553 const GURL kManifestUrl2("http://blah/manifest2"); 550 const GURL kManifestUrl2("http://blah/manifest2");
554 const GURL kOrigin(kManifestUrl.GetOrigin()); 551 const GURL kOrigin(kManifestUrl.GetOrigin());
555 const GURL kOtherOriginManifestUrl("http://other/manifest"); 552 const GURL kOtherOriginManifestUrl("http://other/manifest");
556 const GURL kOtherOrigin(kOtherOriginManifestUrl.GetOrigin()); 553 const GURL kOtherOrigin(kOtherOriginManifestUrl.GetOrigin());
557 554
558 const FilePath kEmptyPath; 555 const FilePath kEmptyPath;
559 AppCacheDatabase db(kEmptyPath); 556 AppCacheDatabase db(kEmptyPath);
560 EXPECT_TRUE(db.LazyOpen(true)); 557 EXPECT_TRUE(db.LazyOpen(true));
561 558
562 scoped_refptr<TestErrorDelegate> error_delegate(new TestErrorDelegate); 559 db.db_->set_error_delegate(new TestErrorDelegate());
563 db.db_->set_error_delegate(error_delegate);
564 560
565 std::vector<AppCacheDatabase::CacheRecord> cache_records; 561 std::vector<AppCacheDatabase::CacheRecord> cache_records;
566 EXPECT_EQ(0, db.GetOriginUsage(kOrigin)); 562 EXPECT_EQ(0, db.GetOriginUsage(kOrigin));
567 EXPECT_TRUE(db.FindCachesForOrigin(kOrigin, &cache_records)); 563 EXPECT_TRUE(db.FindCachesForOrigin(kOrigin, &cache_records));
568 EXPECT_TRUE(cache_records.empty()); 564 EXPECT_TRUE(cache_records.empty());
569 565
570 AppCacheDatabase::GroupRecord group_record; 566 AppCacheDatabase::GroupRecord group_record;
571 group_record.group_id = 1; 567 group_record.group_id = 1;
572 group_record.manifest_url = kManifestUrl; 568 group_record.manifest_url = kManifestUrl;
573 group_record.origin = kOrigin; 569 group_record.origin = kOrigin;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 827
832 EXPECT_EQ(i, fallbacks[i].cache_id); 828 EXPECT_EQ(i, fallbacks[i].cache_id);
833 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[i].type); 829 EXPECT_EQ(FALLBACK_NAMESPACE, fallbacks[i].type);
834 EXPECT_EQ(kMockOrigin, fallbacks[i].origin); 830 EXPECT_EQ(kMockOrigin, fallbacks[i].origin);
835 EXPECT_EQ(expected_namespace_url, fallbacks[i].namespace_url); 831 EXPECT_EQ(expected_namespace_url, fallbacks[i].namespace_url);
836 EXPECT_EQ(expected_target_url, fallbacks[i].target_url); 832 EXPECT_EQ(expected_target_url, fallbacks[i].target_url);
837 } 833 }
838 } 834 }
839 835
840 } // namespace appcache 836 } // namespace appcache
OLDNEW
« no previous file with comments | « sql/statement_unittest.cc ('k') | webkit/database/databases_table_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698