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 "chrome/browser/browsing_data_database_helper.h" | 5 #include "chrome/browser/browsing_data_database_helper.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "chrome/test/testing_profile.h" | 8 #include "chrome/test/testing_profile.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 TestingProfile profile; | 39 TestingProfile profile; |
40 | 40 |
41 const GURL origin1("http://host1:1/"); | 41 const GURL origin1("http://host1:1/"); |
42 const GURL origin2("http://host2:1/"); | 42 const GURL origin2("http://host2:1/"); |
43 const char origin_str1[] = "http_host1_1"; | 43 const char origin_str1[] = "http_host1_1"; |
44 const char origin_str2[] = "http_host2_1"; | 44 const char origin_str2[] = "http_host2_1"; |
45 const char db1[] = "db1"; | 45 const char db1[] = "db1"; |
46 const char db2[] = "db2"; | 46 const char db2[] = "db2"; |
47 const char db3[] = "db3"; | 47 const char db3[] = "db3"; |
48 | 48 |
49 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper = | 49 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( |
50 new CannedBrowsingDataDatabaseHelper(&profile); | 50 new CannedBrowsingDataDatabaseHelper(&profile)); |
51 helper->AddDatabase(origin1, db1, ""); | 51 helper->AddDatabase(origin1, db1, ""); |
52 helper->AddDatabase(origin1, db2, ""); | 52 helper->AddDatabase(origin1, db2, ""); |
53 helper->AddDatabase(origin2, db3, ""); | 53 helper->AddDatabase(origin2, db3, ""); |
54 | 54 |
55 TestCompletionCallback callback; | 55 TestCompletionCallback callback; |
56 helper->StartFetching( | 56 helper->StartFetching( |
57 NewCallback(&callback, &TestCompletionCallback::callback)); | 57 NewCallback(&callback, &TestCompletionCallback::callback)); |
58 ASSERT_TRUE(callback.have_result()); | 58 ASSERT_TRUE(callback.have_result()); |
59 | 59 |
60 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result = | 60 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result = |
61 callback.result(); | 61 callback.result(); |
62 | 62 |
63 ASSERT_EQ(3u, result.size()); | 63 ASSERT_EQ(3u, result.size()); |
64 EXPECT_STREQ(origin_str1, result[0].origin_identifier.c_str()); | 64 EXPECT_STREQ(origin_str1, result[0].origin_identifier.c_str()); |
65 EXPECT_STREQ(db1, result[0].database_name.c_str()); | 65 EXPECT_STREQ(db1, result[0].database_name.c_str()); |
66 EXPECT_STREQ(origin_str1, result[1].origin_identifier.c_str()); | 66 EXPECT_STREQ(origin_str1, result[1].origin_identifier.c_str()); |
67 EXPECT_STREQ(db2, result[1].database_name.c_str()); | 67 EXPECT_STREQ(db2, result[1].database_name.c_str()); |
68 EXPECT_STREQ(origin_str2, result[2].origin_identifier.c_str()); | 68 EXPECT_STREQ(origin_str2, result[2].origin_identifier.c_str()); |
69 EXPECT_STREQ(db3, result[2].database_name.c_str()); | 69 EXPECT_STREQ(db3, result[2].database_name.c_str()); |
70 } | 70 } |
71 | 71 |
72 TEST(CannedBrowsingDataDatabaseTest, Unique) { | 72 TEST(CannedBrowsingDataDatabaseTest, Unique) { |
73 TestingProfile profile; | 73 TestingProfile profile; |
74 | 74 |
75 const GURL origin("http://host1:1/"); | 75 const GURL origin("http://host1:1/"); |
76 const char origin_str[] = "http_host1_1"; | 76 const char origin_str[] = "http_host1_1"; |
77 const char db[] = "db1"; | 77 const char db[] = "db1"; |
78 | 78 |
79 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper = | 79 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( |
80 new CannedBrowsingDataDatabaseHelper(&profile); | 80 new CannedBrowsingDataDatabaseHelper(&profile)); |
81 helper->AddDatabase(origin, db, ""); | 81 helper->AddDatabase(origin, db, ""); |
82 helper->AddDatabase(origin, db, ""); | 82 helper->AddDatabase(origin, db, ""); |
83 | 83 |
84 TestCompletionCallback callback; | 84 TestCompletionCallback callback; |
85 helper->StartFetching( | 85 helper->StartFetching( |
86 NewCallback(&callback, &TestCompletionCallback::callback)); | 86 NewCallback(&callback, &TestCompletionCallback::callback)); |
87 ASSERT_TRUE(callback.have_result()); | 87 ASSERT_TRUE(callback.have_result()); |
88 | 88 |
89 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result = | 89 std::vector<BrowsingDataDatabaseHelper::DatabaseInfo> result = |
90 callback.result(); | 90 callback.result(); |
91 | 91 |
92 ASSERT_EQ(1u, result.size()); | 92 ASSERT_EQ(1u, result.size()); |
93 EXPECT_STREQ(origin_str, result[0].origin_identifier.c_str()); | 93 EXPECT_STREQ(origin_str, result[0].origin_identifier.c_str()); |
94 EXPECT_STREQ(db, result[0].database_name.c_str()); | 94 EXPECT_STREQ(db, result[0].database_name.c_str()); |
95 } | 95 } |
96 | 96 |
97 TEST(CannedBrowsingDataDatabaseTest, Empty) { | 97 TEST(CannedBrowsingDataDatabaseTest, Empty) { |
98 TestingProfile profile; | 98 TestingProfile profile; |
99 | 99 |
100 const GURL origin("http://host1:1/"); | 100 const GURL origin("http://host1:1/"); |
101 const char db[] = "db1"; | 101 const char db[] = "db1"; |
102 | 102 |
103 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper = | 103 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( |
104 new CannedBrowsingDataDatabaseHelper(&profile); | 104 new CannedBrowsingDataDatabaseHelper(&profile)); |
105 | 105 |
106 ASSERT_TRUE(helper->empty()); | 106 ASSERT_TRUE(helper->empty()); |
107 helper->AddDatabase(origin, db, ""); | 107 helper->AddDatabase(origin, db, ""); |
108 ASSERT_FALSE(helper->empty()); | 108 ASSERT_FALSE(helper->empty()); |
109 helper->Reset(); | 109 helper->Reset(); |
110 ASSERT_TRUE(helper->empty()); | 110 ASSERT_TRUE(helper->empty()); |
111 } | 111 } |
OLD | NEW |