| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "chrome/browser/history/url_database.h" | 8 #include "chrome/browser/history/url_database.h" |
| 9 #include "chrome/common/sqlite_compiled_statement.h" | 9 #include "chrome/common/sqlite_compiled_statement.h" |
| 10 #include "chrome/common/sqlite_utils.h" | 10 #include "chrome/common/sqlite_utils.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 std::wstring db_file_; | 68 std::wstring db_file_; |
| 69 sqlite3* db_; | 69 sqlite3* db_; |
| 70 SqliteStatementCache* statement_cache_; | 70 SqliteStatementCache* statement_cache_; |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 } // namespace | 73 } // namespace |
| 74 | 74 |
| 75 // Test add and query for the URL table in the HistoryDatabase | 75 // Test add and query for the URL table in the HistoryDatabase |
| 76 TEST_F(URLDatabaseTest, AddURL) { | 76 TEST_F(URLDatabaseTest, AddURL) { |
| 77 // first, add two URLs | 77 // first, add two URLs |
| 78 const GURL url1(L"http://www.google.com/"); | 78 const GURL url1("http://www.google.com/"); |
| 79 URLRow url_info1(url1); | 79 URLRow url_info1(url1); |
| 80 url_info1.set_title(L"Google"); | 80 url_info1.set_title(L"Google"); |
| 81 url_info1.set_visit_count(4); | 81 url_info1.set_visit_count(4); |
| 82 url_info1.set_typed_count(2); | 82 url_info1.set_typed_count(2); |
| 83 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); | 83 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); |
| 84 url_info1.set_hidden(false); | 84 url_info1.set_hidden(false); |
| 85 EXPECT_TRUE(AddURL(url_info1)); | 85 EXPECT_TRUE(AddURL(url_info1)); |
| 86 | 86 |
| 87 const GURL url2(L"http://mail.google.com/"); | 87 const GURL url2("http://mail.google.com/"); |
| 88 URLRow url_info2(url2); | 88 URLRow url_info2(url2); |
| 89 url_info2.set_title(L"Google Mail"); | 89 url_info2.set_title(L"Google Mail"); |
| 90 url_info2.set_visit_count(3); | 90 url_info2.set_visit_count(3); |
| 91 url_info2.set_typed_count(0); | 91 url_info2.set_typed_count(0); |
| 92 url_info2.set_last_visit(Time::Now() - TimeDelta::FromDays(2)); | 92 url_info2.set_last_visit(Time::Now() - TimeDelta::FromDays(2)); |
| 93 url_info2.set_hidden(true); | 93 url_info2.set_hidden(true); |
| 94 EXPECT_TRUE(AddURL(url_info2)); | 94 EXPECT_TRUE(AddURL(url_info2)); |
| 95 | 95 |
| 96 // query both of them | 96 // query both of them |
| 97 URLRow info; | 97 URLRow info; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 122 //EXPECT_TRUE(db.DeleteDomain(kDomainID)); | 122 //EXPECT_TRUE(db.DeleteDomain(kDomainID)); |
| 123 | 123 |
| 124 // Make sure the urls have been properly removed | 124 // Make sure the urls have been properly removed |
| 125 // FIXME(ACW) commented out because remove no longer works. | 125 // FIXME(ACW) commented out because remove no longer works. |
| 126 //EXPECT_TRUE(db.GetURLInfo(url1, NULL) == NULL); | 126 //EXPECT_TRUE(db.GetURLInfo(url1, NULL) == NULL); |
| 127 //EXPECT_TRUE(db.GetURLInfo(url2, NULL) == NULL); | 127 //EXPECT_TRUE(db.GetURLInfo(url2, NULL) == NULL); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Tests adding, querying and deleting keyword visits. | 130 // Tests adding, querying and deleting keyword visits. |
| 131 TEST_F(URLDatabaseTest, KeywordSearchTermVisit) { | 131 TEST_F(URLDatabaseTest, KeywordSearchTermVisit) { |
| 132 const GURL url1(L"http://www.google.com/"); | 132 const GURL url1("http://www.google.com/"); |
| 133 URLRow url_info1(url1); | 133 URLRow url_info1(url1); |
| 134 url_info1.set_title(L"Google"); | 134 url_info1.set_title(L"Google"); |
| 135 url_info1.set_visit_count(4); | 135 url_info1.set_visit_count(4); |
| 136 url_info1.set_typed_count(2); | 136 url_info1.set_typed_count(2); |
| 137 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); | 137 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); |
| 138 url_info1.set_hidden(false); | 138 url_info1.set_hidden(false); |
| 139 URLID url_id = AddURL(url_info1); | 139 URLID url_id = AddURL(url_info1); |
| 140 ASSERT_TRUE(url_id != 0); | 140 ASSERT_TRUE(url_id != 0); |
| 141 | 141 |
| 142 // Add a keyword visit. | 142 // Add a keyword visit. |
| 143 ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, 1, L"visit")); | 143 ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, 1, L"visit")); |
| 144 | 144 |
| 145 // Make sure we get it back. | 145 // Make sure we get it back. |
| 146 std::vector<KeywordSearchTermVisit> matches; | 146 std::vector<KeywordSearchTermVisit> matches; |
| 147 GetMostRecentKeywordSearchTerms(1, L"visit", 10, &matches); | 147 GetMostRecentKeywordSearchTerms(1, L"visit", 10, &matches); |
| 148 ASSERT_EQ(1, matches.size()); | 148 ASSERT_EQ(1U, matches.size()); |
| 149 ASSERT_EQ(L"visit", matches[0].term); | 149 ASSERT_EQ(L"visit", matches[0].term); |
| 150 | 150 |
| 151 // Delete the keyword visit. | 151 // Delete the keyword visit. |
| 152 DeleteAllSearchTermsForKeyword(1); | 152 DeleteAllSearchTermsForKeyword(1); |
| 153 | 153 |
| 154 // Make sure we don't get it back when querying. | 154 // Make sure we don't get it back when querying. |
| 155 matches.clear(); | 155 matches.clear(); |
| 156 GetMostRecentKeywordSearchTerms(1, L"visit", 10, &matches); | 156 GetMostRecentKeywordSearchTerms(1, L"visit", 10, &matches); |
| 157 ASSERT_EQ(0, matches.size()); | 157 ASSERT_EQ(0U, matches.size()); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Make sure deleting a URL also deletes a keyword visit. | 160 // Make sure deleting a URL also deletes a keyword visit. |
| 161 TEST_F(URLDatabaseTest, DeleteURLDeletesKeywordSearchTermVisit) { | 161 TEST_F(URLDatabaseTest, DeleteURLDeletesKeywordSearchTermVisit) { |
| 162 const GURL url1(L"http://www.google.com/"); | 162 const GURL url1("http://www.google.com/"); |
| 163 URLRow url_info1(url1); | 163 URLRow url_info1(url1); |
| 164 url_info1.set_title(L"Google"); | 164 url_info1.set_title(L"Google"); |
| 165 url_info1.set_visit_count(4); | 165 url_info1.set_visit_count(4); |
| 166 url_info1.set_typed_count(2); | 166 url_info1.set_typed_count(2); |
| 167 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); | 167 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); |
| 168 url_info1.set_hidden(false); | 168 url_info1.set_hidden(false); |
| 169 URLID url_id = AddURL(url_info1); | 169 URLID url_id = AddURL(url_info1); |
| 170 ASSERT_TRUE(url_id != 0); | 170 ASSERT_TRUE(url_id != 0); |
| 171 | 171 |
| 172 // Add a keyword visit. | 172 // Add a keyword visit. |
| 173 ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, 1, L"visit")); | 173 ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, 1, L"visit")); |
| 174 | 174 |
| 175 // Delete the url. | 175 // Delete the url. |
| 176 ASSERT_TRUE(DeleteURLRow(url_id)); | 176 ASSERT_TRUE(DeleteURLRow(url_id)); |
| 177 | 177 |
| 178 // Make sure the keyword visit was deleted. | 178 // Make sure the keyword visit was deleted. |
| 179 std::vector<KeywordSearchTermVisit> matches; | 179 std::vector<KeywordSearchTermVisit> matches; |
| 180 GetMostRecentKeywordSearchTerms(1, L"visit", 10, &matches); | 180 GetMostRecentKeywordSearchTerms(1, L"visit", 10, &matches); |
| 181 ASSERT_EQ(0, matches.size()); | 181 ASSERT_EQ(0U, matches.size()); |
| 182 } | 182 } |
| 183 | 183 |
| 184 } // namespace history | 184 } // namespace history |
| OLD | NEW |