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

Side by Side Diff: chrome/browser/browsing_data_database_helper_unittest.cc

Issue 3178001: Delete callbacks after use in canned browsing data helpers. (Closed)
Patch Set: Created 10 years, 4 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
OLDNEW
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 "chrome/browser/browsing_data_database_helper.h" 5 #include "chrome/browser/browsing_data_database_helper.h"
6 6
7 #include "chrome/test/testing_profile.h" 7 #include "chrome/test/testing_profile.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace { 10 namespace {
11 class TestCompletionCallback 11 class TestCompletionCallback {
12 : public CallbackRunner<Tuple1<
13 const std::vector<BrowsingDataDatabaseHelper::DatabaseInfo>& > > {
14 public: 12 public:
15 TestCompletionCallback() 13 TestCompletionCallback()
16 : have_result_(false) { 14 : have_result_(false) {
17 } 15 }
18 16
19 bool have_result() const { return have_result_; } 17 bool have_result() const { return have_result_; }
20 18
21 const std::vector<BrowsingDataDatabaseHelper::DatabaseInfo>& result() { 19 const std::vector<BrowsingDataDatabaseHelper::DatabaseInfo>& result() {
22 return result_; 20 return result_;
23 } 21 }
24 22
25 virtual void RunWithParams( 23 void callback(const std::vector<
26 const Tuple1<const std::vector< 24 BrowsingDataDatabaseHelper::DatabaseInfo>& info) {
27 BrowsingDataDatabaseHelper::DatabaseInfo>& >& params) {
28 have_result_ = true; 25 have_result_ = true;
29 result_ = params.a; 26 result_ = info;
30 } 27 }
31 28
32 private: 29 private:
33 bool have_result_; 30 bool have_result_;
34 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result_; 31 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result_;
35 32
36 DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback); 33 DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback);
37 }; 34 };
38 } // namespace 35 } // namespace
39 36
40 TEST(CannedBrowsingDataDatabaseTest, AddDatabase) { 37 TEST(CannedBrowsingDataDatabaseTest, AddDatabase) {
41 TestingProfile profile; 38 TestingProfile profile;
42 39
43 const GURL origin1("http://host1:1/"); 40 const GURL origin1("http://host1:1/");
44 const GURL origin2("http://host2:1/"); 41 const GURL origin2("http://host2:1/");
45 const char origin_str1[] = "http_host1_1"; 42 const char origin_str1[] = "http_host1_1";
46 const char origin_str2[] = "http_host2_1"; 43 const char origin_str2[] = "http_host2_1";
47 const char db1[] = "db1"; 44 const char db1[] = "db1";
48 const char db2[] = "db2"; 45 const char db2[] = "db2";
49 const char db3[] = "db3"; 46 const char db3[] = "db3";
50 47
51 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper = 48 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper =
52 new CannedBrowsingDataDatabaseHelper(&profile); 49 new CannedBrowsingDataDatabaseHelper(&profile);
53 helper->AddDatabase(origin1, db1, ""); 50 helper->AddDatabase(origin1, db1, "");
54 helper->AddDatabase(origin1, db2, ""); 51 helper->AddDatabase(origin1, db2, "");
55 helper->AddDatabase(origin2, db3, ""); 52 helper->AddDatabase(origin2, db3, "");
56 53
57 TestCompletionCallback callback; 54 TestCompletionCallback callback;
58 helper->StartFetching(&callback); 55 helper->StartFetching(
56 NewCallback(&callback, &TestCompletionCallback::callback));
59 ASSERT_TRUE(callback.have_result()); 57 ASSERT_TRUE(callback.have_result());
60 58
61 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result = 59 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result =
62 callback.result(); 60 callback.result();
63 61
64 ASSERT_EQ(3u, result.size()); 62 ASSERT_EQ(3u, result.size());
65 EXPECT_STREQ(origin_str1, result[0].origin_identifier.c_str()); 63 EXPECT_STREQ(origin_str1, result[0].origin_identifier.c_str());
66 EXPECT_STREQ(db1, result[0].database_name.c_str()); 64 EXPECT_STREQ(db1, result[0].database_name.c_str());
67 EXPECT_STREQ(origin_str1, result[1].origin_identifier.c_str()); 65 EXPECT_STREQ(origin_str1, result[1].origin_identifier.c_str());
68 EXPECT_STREQ(db2, result[1].database_name.c_str()); 66 EXPECT_STREQ(db2, result[1].database_name.c_str());
69 EXPECT_STREQ(origin_str2, result[2].origin_identifier.c_str()); 67 EXPECT_STREQ(origin_str2, result[2].origin_identifier.c_str());
70 EXPECT_STREQ(db3, result[2].database_name.c_str()); 68 EXPECT_STREQ(db3, result[2].database_name.c_str());
71 } 69 }
72 70
73 TEST(CannedBrowsingDataDatabaseTest, Unique) { 71 TEST(CannedBrowsingDataDatabaseTest, Unique) {
74 TestingProfile profile; 72 TestingProfile profile;
75 73
76 const GURL origin("http://host1:1/"); 74 const GURL origin("http://host1:1/");
77 const char origin_str[] = "http_host1_1"; 75 const char origin_str[] = "http_host1_1";
78 const char db[] = "db1"; 76 const char db[] = "db1";
79 77
80 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper = 78 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper =
81 new CannedBrowsingDataDatabaseHelper(&profile); 79 new CannedBrowsingDataDatabaseHelper(&profile);
82 helper->AddDatabase(origin, db, ""); 80 helper->AddDatabase(origin, db, "");
83 helper->AddDatabase(origin, db, ""); 81 helper->AddDatabase(origin, db, "");
84 82
85 TestCompletionCallback callback; 83 TestCompletionCallback callback;
86 helper->StartFetching(&callback); 84 helper->StartFetching(
85 NewCallback(&callback, &TestCompletionCallback::callback));
87 ASSERT_TRUE(callback.have_result()); 86 ASSERT_TRUE(callback.have_result());
88 87
89 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result = 88 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result =
90 callback.result(); 89 callback.result();
91 90
92 ASSERT_EQ(1u, result.size()); 91 ASSERT_EQ(1u, result.size());
93 EXPECT_STREQ(origin_str, result[0].origin_identifier.c_str()); 92 EXPECT_STREQ(origin_str, result[0].origin_identifier.c_str());
94 EXPECT_STREQ(db, result[0].database_name.c_str()); 93 EXPECT_STREQ(db, result[0].database_name.c_str());
95 } 94 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_database_helper.cc ('k') | chrome/browser/browsing_data_local_storage_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698