OLD | NEW |
1 // Copyright (c) 2009 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 "app/sql/connection.h" | 5 #include "app/sql/connection.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/history/url_database.h" | 11 #include "chrome/browser/history/url_database.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 // Provided for URL/VisitDatabase. | 61 // Provided for URL/VisitDatabase. |
62 virtual sql::Connection& GetDB() { | 62 virtual sql::Connection& GetDB() { |
63 return db_; | 63 return db_; |
64 } | 64 } |
65 | 65 |
66 FilePath db_file_; | 66 FilePath db_file_; |
67 sql::Connection db_; | 67 sql::Connection db_; |
68 }; | 68 }; |
69 | 69 |
70 // Test add and query for the URL table in the HistoryDatabase | 70 // Test add and query for the URL table in the HistoryDatabase. |
71 TEST_F(URLDatabaseTest, AddURL) { | 71 TEST_F(URLDatabaseTest, AddURL) { |
72 // first, add two URLs | 72 // First, add two URLs. |
73 const GURL url1("http://www.google.com/"); | 73 const GURL url1("http://www.google.com/"); |
74 URLRow url_info1(url1); | 74 URLRow url_info1(url1); |
75 url_info1.set_title(UTF8ToUTF16("Google")); | 75 url_info1.set_title(UTF8ToUTF16("Google")); |
76 url_info1.set_visit_count(4); | 76 url_info1.set_visit_count(4); |
77 url_info1.set_typed_count(2); | 77 url_info1.set_typed_count(2); |
78 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); | 78 url_info1.set_last_visit(Time::Now() - TimeDelta::FromDays(1)); |
79 url_info1.set_hidden(false); | 79 url_info1.set_hidden(false); |
80 EXPECT_TRUE(AddURL(url_info1)); | 80 EXPECT_TRUE(AddURL(url_info1)); |
81 | 81 |
82 const GURL url2("http://mail.google.com/"); | 82 const GURL url2("http://mail.google.com/"); |
83 URLRow url_info2(url2); | 83 URLRow url_info2(url2); |
84 url_info2.set_title(UTF8ToUTF16("Google Mail")); | 84 url_info2.set_title(UTF8ToUTF16("Google Mail")); |
85 url_info2.set_visit_count(3); | 85 url_info2.set_visit_count(3); |
86 url_info2.set_typed_count(0); | 86 url_info2.set_typed_count(0); |
87 url_info2.set_last_visit(Time::Now() - TimeDelta::FromDays(2)); | 87 url_info2.set_last_visit(Time::Now() - TimeDelta::FromDays(2)); |
88 url_info2.set_hidden(true); | 88 url_info2.set_hidden(true); |
89 EXPECT_TRUE(AddURL(url_info2)); | 89 EXPECT_TRUE(AddURL(url_info2)); |
90 | 90 |
91 // query both of them | 91 // Query both of them. |
92 URLRow info; | 92 URLRow info; |
93 EXPECT_TRUE(GetRowForURL(url1, &info)); | 93 EXPECT_TRUE(GetRowForURL(url1, &info)); |
94 EXPECT_TRUE(IsURLRowEqual(url_info1, info)); | 94 EXPECT_TRUE(IsURLRowEqual(url_info1, info)); |
95 URLID id2 = GetRowForURL(url2, &info); | 95 URLID id2 = GetRowForURL(url2, &info); |
96 EXPECT_TRUE(id2); | 96 EXPECT_TRUE(id2); |
97 EXPECT_TRUE(IsURLRowEqual(url_info2, info)); | 97 EXPECT_TRUE(IsURLRowEqual(url_info2, info)); |
98 | 98 |
99 // update the second | 99 // Update the second. |
100 url_info2.set_title(UTF8ToUTF16("Google Mail Too")); | 100 url_info2.set_title(UTF8ToUTF16("Google Mail Too")); |
101 url_info2.set_visit_count(4); | 101 url_info2.set_visit_count(4); |
102 url_info2.set_typed_count(1); | 102 url_info2.set_typed_count(1); |
103 url_info2.set_typed_count(91011); | 103 url_info2.set_typed_count(91011); |
104 url_info2.set_hidden(false); | 104 url_info2.set_hidden(false); |
105 EXPECT_TRUE(UpdateURLRow(id2, url_info2)); | 105 EXPECT_TRUE(UpdateURLRow(id2, url_info2)); |
106 | 106 |
107 // make sure it got updated | 107 // Make sure it got updated. |
108 URLRow info2; | 108 URLRow info2; |
109 EXPECT_TRUE(GetRowForURL(url2, &info2)); | 109 EXPECT_TRUE(GetRowForURL(url2, &info2)); |
110 EXPECT_TRUE(IsURLRowEqual(url_info2, info2)); | 110 EXPECT_TRUE(IsURLRowEqual(url_info2, info2)); |
111 | 111 |
112 // query a nonexistant URL | 112 // Query a nonexistent URL. |
113 EXPECT_EQ(0, GetRowForURL(GURL("http://news.google.com/"), &info)); | 113 EXPECT_EQ(0, GetRowForURL(GURL("http://news.google.com/"), &info)); |
114 | 114 |
115 // Delete all urls in the domain | 115 // Delete all urls in the domain. |
116 // TODO(acw): test the new url based delete domain | 116 // TODO(acw): test the new url based delete domain |
117 // EXPECT_TRUE(db.DeleteDomain(kDomainID)); | 117 // EXPECT_TRUE(db.DeleteDomain(kDomainID)); |
118 | 118 |
119 // Make sure the urls have been properly removed | 119 // Make sure the urls have been properly removed. |
120 // TODO(acw): commented out because remove no longer works. | 120 // TODO(acw): commented out because remove no longer works. |
121 // EXPECT_TRUE(db.GetURLInfo(url1, NULL) == NULL); | 121 // EXPECT_TRUE(db.GetURLInfo(url1, NULL) == NULL); |
122 // EXPECT_TRUE(db.GetURLInfo(url2, NULL) == NULL); | 122 // EXPECT_TRUE(db.GetURLInfo(url2, NULL) == NULL); |
123 } | 123 } |
124 | 124 |
125 // Tests adding, querying and deleting keyword visits. | 125 // Tests adding, querying and deleting keyword visits. |
126 TEST_F(URLDatabaseTest, KeywordSearchTermVisit) { | 126 TEST_F(URLDatabaseTest, KeywordSearchTermVisit) { |
127 const GURL url1("http://www.google.com/"); | 127 const GURL url1("http://www.google.com/"); |
128 URLRow url_info1(url1); | 128 URLRow url_info1(url1); |
129 url_info1.set_title(UTF8ToUTF16("Google")); | 129 url_info1.set_title(UTF8ToUTF16("Google")); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // Delete the url. | 170 // Delete the url. |
171 ASSERT_TRUE(DeleteURLRow(url_id)); | 171 ASSERT_TRUE(DeleteURLRow(url_id)); |
172 | 172 |
173 // Make sure the keyword visit was deleted. | 173 // Make sure the keyword visit was deleted. |
174 std::vector<KeywordSearchTermVisit> matches; | 174 std::vector<KeywordSearchTermVisit> matches; |
175 GetMostRecentKeywordSearchTerms(1, UTF8ToUTF16("visit"), 10, &matches); | 175 GetMostRecentKeywordSearchTerms(1, UTF8ToUTF16("visit"), 10, &matches); |
176 ASSERT_EQ(0U, matches.size()); | 176 ASSERT_EQ(0U, matches.size()); |
177 } | 177 } |
178 | 178 |
179 } // namespace history | 179 } // namespace history |
OLD | NEW |