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

Side by Side Diff: chrome/browser/history/text_database_manager_unittest.cc

Issue 9316129: Don't strip punctuation inside quotes in history search queries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change non-breaking characters to '.' and '-'. Created 8 years, 10 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/history/text_database_manager.h" 9 #include "chrome/browser/history/text_database_manager.h"
10 #include "chrome/browser/history/visit_database.h" 10 #include "chrome/browser/history/visit_database.h"
(...skipping 14 matching lines...) Expand all
25 25
26 const char* kURL2 = "http://www.google.com/qwer"; 26 const char* kURL2 = "http://www.google.com/qwer";
27 const char* kTitle2 = "Google B"; 27 const char* kTitle2 = "Google B";
28 const char* kBody2 = "FOO two."; 28 const char* kBody2 = "FOO two.";
29 29
30 const char* kURL3 = "http://www.google.com/zxcv"; 30 const char* kURL3 = "http://www.google.com/zxcv";
31 const char* kTitle3 = "Google C"; 31 const char* kTitle3 = "Google C";
32 const char* kBody3 = "FOO drei"; 32 const char* kBody3 = "FOO drei";
33 33
34 const char* kURL4 = "http://www.google.com/hjkl"; 34 const char* kURL4 = "http://www.google.com/hjkl";
35 const char* kTitle4 = "Google D"; 35 const char* kTitle4 = "Google de";
36 const char* kBody4 = "FOO lalala four."; 36 const char* kBody4 = "FOO lalala four.";
37 37
38 const char* kURL5 = "http://www.google.com/uiop"; 38 const char* kURL5 = "http://www.google.de/s?q=mar%10&num=66";
39 const char* kTitle5 = "Google cinq"; 39 const char* kTitle5 = "Google cinq";
40 const char* kBody5 = "FOO page one."; 40 const char* kBody5 = "FOO page one. Including: punctuation.";
41 41
42 // This provides a simple implementation of a URL+VisitDatabase using an 42 // This provides a simple implementation of a URL+VisitDatabase using an
43 // in-memory sqlite connection. The text database manager expects to be able to 43 // in-memory sqlite connection. The text database manager expects to be able to
44 // update the visit database to keep in sync. 44 // update the visit database to keep in sync.
45 class InMemDB : public URLDatabase, public VisitDatabase { 45 class InMemDB : public URLDatabase, public VisitDatabase {
46 public: 46 public:
47 InMemDB() { 47 InMemDB() {
48 EXPECT_TRUE(db_.OpenInMemory()); 48 EXPECT_TRUE(db_.OpenInMemory());
49 CreateURLTable(false); 49 CreateURLTable(false);
50 InitVisitTable(); 50 InitVisitTable();
(...skipping 25 matching lines...) Expand all
76 visit_row.url_id = 1; 76 visit_row.url_id = 1;
77 visit_row.visit_time = Time::FromUTCExploded(exploded); 77 visit_row.visit_time = Time::FromUTCExploded(exploded);
78 visit_row.referring_visit = 0; 78 visit_row.referring_visit = 0;
79 visit_row.transition = content::PageTransitionFromInt(0); 79 visit_row.transition = content::PageTransitionFromInt(0);
80 visit_row.segment_id = 0; 80 visit_row.segment_id = 0;
81 visit_row.is_indexed = false; 81 visit_row.is_indexed = false;
82 visit_db->AddVisit(&visit_row, SOURCE_BROWSED); 82 visit_db->AddVisit(&visit_row, SOURCE_BROWSED);
83 83
84 times->push_back(visit_row.visit_time); 84 times->push_back(visit_row.visit_time);
85 manager.AddPageData(GURL(kURL1), visit_row.url_id, visit_row.visit_id, 85 manager.AddPageData(GURL(kURL1), visit_row.url_id, visit_row.visit_id,
86 visit_row.visit_time, UTF8ToUTF16(kTitle1), 86 visit_row.visit_time, ASCIIToUTF16(kTitle1),
87 UTF8ToUTF16(kBody1)); 87 ASCIIToUTF16(kBody1));
88 88
89 exploded.day_of_month++; 89 exploded.day_of_month++;
90 visit_row.url_id = 2; 90 visit_row.url_id = 2;
91 visit_row.visit_time = Time::FromUTCExploded(exploded); 91 visit_row.visit_time = Time::FromUTCExploded(exploded);
92 visit_db->AddVisit(&visit_row, SOURCE_BROWSED); 92 visit_db->AddVisit(&visit_row, SOURCE_BROWSED);
93 times->push_back(visit_row.visit_time); 93 times->push_back(visit_row.visit_time);
94 manager.AddPageData(GURL(kURL2), visit_row.url_id, visit_row.visit_id, 94 manager.AddPageData(GURL(kURL2), visit_row.url_id, visit_row.visit_id,
95 visit_row.visit_time, UTF8ToUTF16(kTitle2), 95 visit_row.visit_time, ASCIIToUTF16(kTitle2),
96 UTF8ToUTF16(kBody2)); 96 ASCIIToUTF16(kBody2));
97 97
98 exploded.day_of_month++; 98 exploded.day_of_month++;
99 visit_row.url_id = 2; 99 visit_row.url_id = 2;
100 visit_row.visit_time = Time::FromUTCExploded(exploded); 100 visit_row.visit_time = Time::FromUTCExploded(exploded);
101 visit_db->AddVisit(&visit_row, SOURCE_BROWSED); 101 visit_db->AddVisit(&visit_row, SOURCE_BROWSED);
102 times->push_back(visit_row.visit_time); 102 times->push_back(visit_row.visit_time);
103 manager.AddPageData(GURL(kURL3), visit_row.url_id, visit_row.visit_id, 103 manager.AddPageData(GURL(kURL3), visit_row.url_id, visit_row.visit_id,
104 visit_row.visit_time, UTF8ToUTF16(kTitle3), 104 visit_row.visit_time, ASCIIToUTF16(kTitle3),
105 UTF8ToUTF16(kBody3)); 105 ASCIIToUTF16(kBody3));
106 106
107 // Put the next ones in the next month. 107 // Put the next ones in the next month.
108 exploded.month++; 108 exploded.month++;
109 visit_row.url_id = 2; 109 visit_row.url_id = 2;
110 visit_row.visit_time = Time::FromUTCExploded(exploded); 110 visit_row.visit_time = Time::FromUTCExploded(exploded);
111 visit_db->AddVisit(&visit_row, SOURCE_BROWSED); 111 visit_db->AddVisit(&visit_row, SOURCE_BROWSED);
112 times->push_back(visit_row.visit_time); 112 times->push_back(visit_row.visit_time);
113 manager.AddPageData(GURL(kURL4), visit_row.url_id, visit_row.visit_id, 113 manager.AddPageData(GURL(kURL4), visit_row.url_id, visit_row.visit_id,
114 visit_row.visit_time, UTF8ToUTF16(kTitle4), 114 visit_row.visit_time, ASCIIToUTF16(kTitle4),
115 UTF8ToUTF16(kBody4)); 115 ASCIIToUTF16(kBody4));
116 116
117 exploded.day_of_month++; 117 exploded.day_of_month++;
118 visit_row.url_id = 2; 118 visit_row.url_id = 2;
119 visit_row.visit_time = Time::FromUTCExploded(exploded); 119 visit_row.visit_time = Time::FromUTCExploded(exploded);
120 visit_db->AddVisit(&visit_row, SOURCE_BROWSED); 120 visit_db->AddVisit(&visit_row, SOURCE_BROWSED);
121 times->push_back(visit_row.visit_time); 121 times->push_back(visit_row.visit_time);
122 manager.AddPageData(GURL(kURL5), visit_row.url_id, visit_row.visit_id, 122 manager.AddPageData(GURL(kURL5), visit_row.url_id, visit_row.visit_id,
123 visit_row.visit_time, UTF8ToUTF16(kTitle5), 123 visit_row.visit_time, ASCIIToUTF16(kTitle5),
124 UTF8ToUTF16(kBody5)); 124 ASCIIToUTF16(kBody5));
125 125
126 // Put the first one in again in the second month. 126 // Put the first one in again in the second month.
127 exploded.day_of_month++; 127 exploded.day_of_month++;
128 visit_row.url_id = 2; 128 visit_row.url_id = 2;
129 visit_row.visit_time = Time::FromUTCExploded(exploded); 129 visit_row.visit_time = Time::FromUTCExploded(exploded);
130 visit_db->AddVisit(&visit_row, SOURCE_BROWSED); 130 visit_db->AddVisit(&visit_row, SOURCE_BROWSED);
131 times->push_back(visit_row.visit_time); 131 times->push_back(visit_row.visit_time);
132 manager.AddPageData(GURL(kURL1), visit_row.url_id, visit_row.visit_id, 132 manager.AddPageData(GURL(kURL1), visit_row.url_id, visit_row.visit_id,
133 visit_row.visit_time, UTF8ToUTF16(kTitle1), 133 visit_row.visit_time, ASCIIToUTF16(kTitle1),
134 UTF8ToUTF16(kBody1)); 134 ASCIIToUTF16(kBody1));
135 } 135 }
136 136
137 bool ResultsHaveURL(const std::vector<TextDatabase::Match>& results, 137 bool ResultsHaveURL(const std::vector<TextDatabase::Match>& results,
138 const char* url) { 138 const char* url) {
139 GURL gurl(url); 139 GURL gurl(url);
140 for (size_t i = 0; i < results.size(); i++) { 140 for (size_t i = 0; i < results.size(); i++) {
141 if (results[i].url == gurl) 141 if (results[i].url == gurl)
142 return true; 142 return true;
143 } 143 }
144 return false; 144 return false;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 ASSERT_TRUE(manager.Init(NULL)); 176 ASSERT_TRUE(manager.Init(NULL));
177 177
178 std::vector<Time> times; 178 std::vector<Time> times;
179 AddAllPages(manager, &visit_db, &times); 179 AddAllPages(manager, &visit_db, &times);
180 180
181 QueryOptions options; 181 QueryOptions options;
182 options.begin_time = times[0] - TimeDelta::FromDays(100); 182 options.begin_time = times[0] - TimeDelta::FromDays(100);
183 options.end_time = times[times.size() - 1] + TimeDelta::FromDays(100); 183 options.end_time = times[times.size() - 1] + TimeDelta::FromDays(100);
184 std::vector<TextDatabase::Match> results; 184 std::vector<TextDatabase::Match> results;
185 Time first_time_searched; 185 Time first_time_searched;
186 manager.GetTextMatches(UTF8ToUTF16("FOO"), options, 186 manager.GetTextMatches(ASCIIToUTF16("FOO"), options,
187 &results, &first_time_searched); 187 &results, &first_time_searched);
188 188
189 // We should have matched every page. 189 // We should have matched every page.
190 EXPECT_EQ(6U, results.size()); 190 EXPECT_EQ(6U, results.size());
191 EXPECT_TRUE(ResultsHaveURL(results, kURL1)); 191 EXPECT_TRUE(ResultsHaveURL(results, kURL1));
192 EXPECT_TRUE(ResultsHaveURL(results, kURL2)); 192 EXPECT_TRUE(ResultsHaveURL(results, kURL2));
193 EXPECT_TRUE(ResultsHaveURL(results, kURL3)); 193 EXPECT_TRUE(ResultsHaveURL(results, kURL3));
194 EXPECT_TRUE(ResultsHaveURL(results, kURL4)); 194 EXPECT_TRUE(ResultsHaveURL(results, kURL4));
195 EXPECT_TRUE(ResultsHaveURL(results, kURL5)); 195 EXPECT_TRUE(ResultsHaveURL(results, kURL5));
196 196
197 // The first time searched should have been the first page's time or before 197 // The first time searched should have been the first page's time or before
198 // (it could have eliminated some time for us). 198 // (it could have eliminated some time for us).
199 EXPECT_TRUE(first_time_searched <= times[0]); 199 EXPECT_TRUE(first_time_searched <= times[0]);
200 } 200 }
201 201
202 // Tests that adding page components piecemeal will get them added properly. 202 // Tests that adding page components piecemeal will get them added properly.
203 // This does not supply a visit to update, this mode is used only by the unit 203 // This does not supply a visit to update, this mode is used only by the unit
204 // tests right now, but we test it anyway. 204 // tests right now, but we test it anyway.
205 TEST_F(TextDatabaseManagerTest, InsertCompleteNoVisit) { 205 TEST_F(TextDatabaseManagerTest, InsertCompleteNoVisit) {
206 ASSERT_TRUE(Init()); 206 ASSERT_TRUE(Init());
207 InMemDB visit_db; 207 InMemDB visit_db;
208 TextDatabaseManager manager(dir_, &visit_db, &visit_db); 208 TextDatabaseManager manager(dir_, &visit_db, &visit_db);
209 ASSERT_TRUE(manager.Init(NULL)); 209 ASSERT_TRUE(manager.Init(NULL));
210 210
211 // First add one without a visit. 211 // First add one without a visit.
212 const GURL url(kURL1); 212 const GURL url(kURL1);
213 manager.AddPageURL(url, 0, 0, Time::Now()); 213 manager.AddPageURL(url, 0, 0, Time::Now());
214 manager.AddPageTitle(url, UTF8ToUTF16(kTitle1)); 214 manager.AddPageTitle(url, ASCIIToUTF16(kTitle1));
215 manager.AddPageContents(url, UTF8ToUTF16(kBody1)); 215 manager.AddPageContents(url, ASCIIToUTF16(kBody1));
216 216
217 // Check that the page got added. 217 // Check that the page got added.
218 QueryOptions options; 218 QueryOptions options;
219 std::vector<TextDatabase::Match> results; 219 std::vector<TextDatabase::Match> results;
220 Time first_time_searched; 220 Time first_time_searched;
221 221
222 manager.GetTextMatches(UTF8ToUTF16("FOO"), options, 222 manager.GetTextMatches(ASCIIToUTF16("FOO"), options,
223 &results, &first_time_searched); 223 &results, &first_time_searched);
224 ASSERT_EQ(1U, results.size()); 224 ASSERT_EQ(1U, results.size());
225 EXPECT_EQ(kTitle1, UTF16ToUTF8(results[0].title)); 225 EXPECT_EQ(kTitle1, UTF16ToUTF8(results[0].title));
226 } 226 }
227 227
228 // Like InsertCompleteNoVisit but specifies a visit to update. We check that the 228 // Like InsertCompleteNoVisit but specifies a visit to update. We check that the
229 // visit was updated properly. 229 // visit was updated properly.
230 TEST_F(TextDatabaseManagerTest, InsertCompleteVisit) { 230 TEST_F(TextDatabaseManagerTest, InsertCompleteVisit) {
231 ASSERT_TRUE(Init()); 231 ASSERT_TRUE(Init());
232 InMemDB visit_db; 232 InMemDB visit_db;
233 TextDatabaseManager manager(dir_, &visit_db, &visit_db); 233 TextDatabaseManager manager(dir_, &visit_db, &visit_db);
234 ASSERT_TRUE(manager.Init(NULL)); 234 ASSERT_TRUE(manager.Init(NULL));
235 235
236 // First add a visit to a page. We can just make up a URL ID since there is 236 // First add a visit to a page. We can just make up a URL ID since there is
237 // not actually any URL database around. 237 // not actually any URL database around.
238 VisitRow visit; 238 VisitRow visit;
239 visit.url_id = 1; 239 visit.url_id = 1;
240 visit.visit_time = Time::Now(); 240 visit.visit_time = Time::Now();
241 visit.referring_visit = 0; 241 visit.referring_visit = 0;
242 visit.transition = content::PAGE_TRANSITION_LINK; 242 visit.transition = content::PAGE_TRANSITION_LINK;
243 visit.segment_id = 0; 243 visit.segment_id = 0;
244 visit.is_indexed = false; 244 visit.is_indexed = false;
245 visit_db.AddVisit(&visit, SOURCE_BROWSED); 245 visit_db.AddVisit(&visit, SOURCE_BROWSED);
246 246
247 // Add a full text indexed entry for that visit. 247 // Add a full text indexed entry for that visit.
248 const GURL url(kURL2); 248 const GURL url(kURL2);
249 manager.AddPageURL(url, visit.url_id, visit.visit_id, visit.visit_time); 249 manager.AddPageURL(url, visit.url_id, visit.visit_id, visit.visit_time);
250 manager.AddPageContents(url, UTF8ToUTF16(kBody2)); 250 manager.AddPageContents(url, ASCIIToUTF16(kBody2));
251 manager.AddPageTitle(url, UTF8ToUTF16(kTitle2)); 251 manager.AddPageTitle(url, ASCIIToUTF16(kTitle2));
252 252
253 // Check that the page got added. 253 // Check that the page got added.
254 QueryOptions options; 254 QueryOptions options;
255 std::vector<TextDatabase::Match> results; 255 std::vector<TextDatabase::Match> results;
256 Time first_time_searched; 256 Time first_time_searched;
257 257
258 manager.GetTextMatches(UTF8ToUTF16("FOO"), options, 258 manager.GetTextMatches(ASCIIToUTF16("FOO"), options,
259 &results, &first_time_searched); 259 &results, &first_time_searched);
260 ASSERT_EQ(1U, results.size()); 260 ASSERT_EQ(1U, results.size());
261 EXPECT_EQ(kTitle2, UTF16ToUTF8(results[0].title)); 261 EXPECT_EQ(kTitle2, UTF16ToUTF8(results[0].title));
262 262
263 // Check that the visit got updated for its new indexed state. 263 // Check that the visit got updated for its new indexed state.
264 VisitRow out_visit; 264 VisitRow out_visit;
265 ASSERT_TRUE(visit_db.GetRowForVisit(visit.visit_id, &out_visit)); 265 ASSERT_TRUE(visit_db.GetRowForVisit(visit.visit_id, &out_visit));
266 EXPECT_TRUE(out_visit.is_indexed); 266 EXPECT_TRUE(out_visit.is_indexed);
267 } 267 }
268 268
269 // Tests that partial inserts that expire are added to the database. 269 // Tests that partial inserts that expire are added to the database.
270 TEST_F(TextDatabaseManagerTest, InsertPartial) { 270 TEST_F(TextDatabaseManagerTest, InsertPartial) {
271 ASSERT_TRUE(Init()); 271 ASSERT_TRUE(Init());
272 InMemDB visit_db; 272 InMemDB visit_db;
273 TextDatabaseManager manager(dir_, &visit_db, &visit_db); 273 TextDatabaseManager manager(dir_, &visit_db, &visit_db);
274 ASSERT_TRUE(manager.Init(NULL)); 274 ASSERT_TRUE(manager.Init(NULL));
275 275
276 // Add the first one with just a URL. 276 // Add the first one with just a URL.
277 GURL url1(kURL1); 277 GURL url1(kURL1);
278 manager.AddPageURL(url1, 0, 0, Time::Now()); 278 manager.AddPageURL(url1, 0, 0, Time::Now());
279 279
280 // Now add a second one with a URL and title. 280 // Now add a second one with a URL and title.
281 GURL url2(kURL2); 281 GURL url2(kURL2);
282 manager.AddPageURL(url2, 0, 0, Time::Now()); 282 manager.AddPageURL(url2, 0, 0, Time::Now());
283 manager.AddPageTitle(url2, UTF8ToUTF16(kTitle2)); 283 manager.AddPageTitle(url2, ASCIIToUTF16(kTitle2));
284 284
285 // The third one has a URL and body. 285 // The third one has a URL and body.
286 GURL url3(kURL3); 286 GURL url3(kURL3);
287 manager.AddPageURL(url3, 0, 0, Time::Now()); 287 manager.AddPageURL(url3, 0, 0, Time::Now());
288 manager.AddPageContents(url3, UTF8ToUTF16(kBody3)); 288 manager.AddPageContents(url3, ASCIIToUTF16(kBody3));
289 289
290 // Expire stuff very fast. This assumes that the time between the first 290 // Expire stuff very fast. This assumes that the time between the first
291 // AddPageURL and this line is less than the expiration time (20 seconds). 291 // AddPageURL and this line is less than the expiration time (20 seconds).
292 TimeTicks added_time = TimeTicks::Now(); 292 TimeTicks added_time = TimeTicks::Now();
293 TimeTicks expire_time = added_time + TimeDelta::FromSeconds(5); 293 TimeTicks expire_time = added_time + TimeDelta::FromSeconds(5);
294 manager.FlushOldChangesForTime(expire_time); 294 manager.FlushOldChangesForTime(expire_time);
295 295
296 // Do a query, nothing should be added yet. 296 // Do a query, nothing should be added yet.
297 QueryOptions options; 297 QueryOptions options;
298 std::vector<TextDatabase::Match> results; 298 std::vector<TextDatabase::Match> results;
299 Time first_time_searched; 299 Time first_time_searched;
300 manager.GetTextMatches(UTF8ToUTF16("google"), options, 300 manager.GetTextMatches(ASCIIToUTF16("google"), options,
301 &results, &first_time_searched); 301 &results, &first_time_searched);
302 ASSERT_EQ(0U, results.size()); 302 ASSERT_EQ(0U, results.size());
303 303
304 // Compute a time threshold that will cause everything to be flushed, and 304 // Compute a time threshold that will cause everything to be flushed, and
305 // poke at the manager's internals to cause this to happen. 305 // poke at the manager's internals to cause this to happen.
306 expire_time = added_time + TimeDelta::FromDays(1); 306 expire_time = added_time + TimeDelta::FromDays(1);
307 manager.FlushOldChangesForTime(expire_time); 307 manager.FlushOldChangesForTime(expire_time);
308 308
309 // Now we should have all 3 URLs added. 309 // Now we should have all 3 URLs added.
310 manager.GetTextMatches(UTF8ToUTF16("google"), options, 310 manager.GetTextMatches(ASCIIToUTF16("google"), options,
311 &results, &first_time_searched); 311 &results, &first_time_searched);
312 ASSERT_EQ(3U, results.size()); 312 ASSERT_EQ(3U, results.size());
313 EXPECT_TRUE(ResultsHaveURL(results, kURL1)); 313 EXPECT_TRUE(ResultsHaveURL(results, kURL1));
314 EXPECT_TRUE(ResultsHaveURL(results, kURL2)); 314 EXPECT_TRUE(ResultsHaveURL(results, kURL2));
315 EXPECT_TRUE(ResultsHaveURL(results, kURL3)); 315 EXPECT_TRUE(ResultsHaveURL(results, kURL3));
316 } 316 }
317 317
318 // Tests that partial inserts (due to timeouts) will still get updated if the 318 // Tests that partial inserts (due to timeouts) will still get updated if the
319 // data comes in later. 319 // data comes in later.
320 TEST_F(TextDatabaseManagerTest, PartialComplete) { 320 TEST_F(TextDatabaseManagerTest, PartialComplete) {
321 ASSERT_TRUE(Init()); 321 ASSERT_TRUE(Init());
322 InMemDB visit_db; 322 InMemDB visit_db;
323 TextDatabaseManager manager(dir_, &visit_db, &visit_db); 323 TextDatabaseManager manager(dir_, &visit_db, &visit_db);
324 ASSERT_TRUE(manager.Init(NULL)); 324 ASSERT_TRUE(manager.Init(NULL));
325 325
326 Time added_time = Time::Now(); 326 Time added_time = Time::Now();
327 GURL url(kURL1); 327 GURL url(kURL1);
328 328
329 // We have to have the URL in the URL and visit databases for this test to 329 // We have to have the URL in the URL and visit databases for this test to
330 // work. 330 // work.
331 URLRow url_row(url); 331 URLRow url_row(url);
332 url_row.set_title(UTF8ToUTF16("chocolate")); 332 url_row.set_title(ASCIIToUTF16("chocolate"));
333 URLID url_id = visit_db.AddURL(url_row); 333 URLID url_id = visit_db.AddURL(url_row);
334 ASSERT_TRUE(url_id); 334 ASSERT_TRUE(url_id);
335 VisitRow visit_row; 335 VisitRow visit_row;
336 visit_row.url_id = url_id; 336 visit_row.url_id = url_id;
337 visit_row.visit_time = added_time; 337 visit_row.visit_time = added_time;
338 visit_db.AddVisit(&visit_row, SOURCE_BROWSED); 338 visit_db.AddVisit(&visit_row, SOURCE_BROWSED);
339 339
340 // Add a URL with no title or body, and say that it expired. 340 // Add a URL with no title or body, and say that it expired.
341 manager.AddPageURL(url, 0, 0, added_time); 341 manager.AddPageURL(url, 0, 0, added_time);
342 TimeTicks expire_time = TimeTicks::Now() + TimeDelta::FromDays(1); 342 TimeTicks expire_time = TimeTicks::Now() + TimeDelta::FromDays(1);
343 manager.FlushOldChangesForTime(expire_time); 343 manager.FlushOldChangesForTime(expire_time);
344 344
345 // Add the title. We should be able to query based on that. The title in the 345 // Add the title. We should be able to query based on that. The title in the
346 // URL row we set above should not come into the picture. 346 // URL row we set above should not come into the picture.
347 manager.AddPageTitle(url, UTF8ToUTF16("Some unique title")); 347 manager.AddPageTitle(url, ASCIIToUTF16("Some unique title"));
348 Time first_time_searched; 348 Time first_time_searched;
349 QueryOptions options; 349 QueryOptions options;
350 std::vector<TextDatabase::Match> results; 350 std::vector<TextDatabase::Match> results;
351 manager.GetTextMatches(UTF8ToUTF16("unique"), options, 351 manager.GetTextMatches(ASCIIToUTF16("unique"), options,
352 &results, &first_time_searched); 352 &results, &first_time_searched);
353 EXPECT_EQ(1U, results.size()); 353 EXPECT_EQ(1U, results.size());
354 manager.GetTextMatches(UTF8ToUTF16("chocolate"), options, 354 manager.GetTextMatches(ASCIIToUTF16("chocolate"), options,
355 &results, &first_time_searched); 355 &results, &first_time_searched);
356 EXPECT_EQ(0U, results.size()); 356 EXPECT_EQ(0U, results.size());
357 357
358 // Now add the body, which should be queryable. 358 // Now add the body, which should be queryable.
359 manager.AddPageContents(url, UTF8ToUTF16("Very awesome body")); 359 manager.AddPageContents(url, ASCIIToUTF16("Very awesome body"));
360 manager.GetTextMatches(UTF8ToUTF16("awesome"), options, &results, &first_time_ searched); 360 manager.GetTextMatches(
361 ASCIIToUTF16("awesome"), options, &results, &first_time_searched);
361 EXPECT_EQ(1U, results.size()); 362 EXPECT_EQ(1U, results.size());
362 363
363 // Adding the body will actually copy the title from the URL table rather 364 // Adding the body will actually copy the title from the URL table rather
364 // than the previously indexed row (we made them not match above). This isn't 365 // than the previously indexed row (we made them not match above). This isn't
365 // necessarily what we want, but it's how it's implemented, and we don't want 366 // necessarily what we want, but it's how it's implemented, and we don't want
366 // to regress it. 367 // to regress it.
367 manager.GetTextMatches(UTF8ToUTF16("chocolate"), options, &results, &first_tim e_searched); 368 manager.GetTextMatches(
369 ASCIIToUTF16("chocolate"), options, &results, &first_time_searched);
368 EXPECT_EQ(1U, results.size()); 370 EXPECT_EQ(1U, results.size());
369 } 371 }
370 372
371 // Tests that changes get properly committed to disk. 373 // Tests that changes get properly committed to disk.
372 TEST_F(TextDatabaseManagerTest, Writing) { 374 TEST_F(TextDatabaseManagerTest, Writing) {
373 ASSERT_TRUE(Init()); 375 ASSERT_TRUE(Init());
374 376
375 QueryOptions options; 377 QueryOptions options;
376 std::vector<TextDatabase::Match> results; 378 std::vector<TextDatabase::Match> results;
377 Time first_time_searched; 379 Time first_time_searched;
378 380
379 InMemDB visit_db; 381 InMemDB visit_db;
380 382
381 // Create the manager and write some stuff to it. 383 // Create the manager and write some stuff to it.
382 { 384 {
383 TextDatabaseManager manager(dir_, &visit_db, &visit_db); 385 TextDatabaseManager manager(dir_, &visit_db, &visit_db);
384 ASSERT_TRUE(manager.Init(NULL)); 386 ASSERT_TRUE(manager.Init(NULL));
385 387
386 std::vector<Time> times; 388 std::vector<Time> times;
387 AddAllPages(manager, &visit_db, &times); 389 AddAllPages(manager, &visit_db, &times);
388 390
389 // We should have matched every page. 391 // We should have matched every page.
390 manager.GetTextMatches(UTF8ToUTF16("FOO"), options, &results, &first_time_se arched); 392 manager.GetTextMatches(
393 ASCIIToUTF16("FOO"), options, &results, &first_time_searched);
391 EXPECT_EQ(6U, results.size()); 394 EXPECT_EQ(6U, results.size());
392 } 395 }
393 results.clear(); 396 results.clear();
394 397
395 // Recreate the manager and make sure it finds the written stuff. 398 // Recreate the manager and make sure it finds the written stuff.
396 { 399 {
397 TextDatabaseManager manager(dir_, &visit_db, &visit_db); 400 TextDatabaseManager manager(dir_, &visit_db, &visit_db);
398 ASSERT_TRUE(manager.Init(NULL)); 401 ASSERT_TRUE(manager.Init(NULL));
399 402
400 // We should have matched every page again. 403 // We should have matched every page again.
401 manager.GetTextMatches(UTF8ToUTF16("FOO"), options, 404 manager.GetTextMatches(ASCIIToUTF16("FOO"), options,
402 &results, &first_time_searched); 405 &results, &first_time_searched);
403 EXPECT_EQ(6U, results.size()); 406 EXPECT_EQ(6U, results.size());
404 } 407 }
405 } 408 }
406 409
407 // Tests that changes get properly committed to disk, as in the Writing test 410 // Tests that changes get properly committed to disk, as in the Writing test
408 // above, but when there is a transaction around the adds. 411 // above, but when there is a transaction around the adds.
409 TEST_F(TextDatabaseManagerTest, WritingTransaction) { 412 TEST_F(TextDatabaseManagerTest, WritingTransaction) {
410 ASSERT_TRUE(Init()); 413 ASSERT_TRUE(Init());
411 414
412 QueryOptions options; 415 QueryOptions options;
413 std::vector<TextDatabase::Match> results; 416 std::vector<TextDatabase::Match> results;
414 Time first_time_searched; 417 Time first_time_searched;
415 418
416 InMemDB visit_db; 419 InMemDB visit_db;
417 420
418 // Create the manager and write some stuff to it. 421 // Create the manager and write some stuff to it.
419 { 422 {
420 TextDatabaseManager manager(dir_, &visit_db, &visit_db); 423 TextDatabaseManager manager(dir_, &visit_db, &visit_db);
421 ASSERT_TRUE(manager.Init(NULL)); 424 ASSERT_TRUE(manager.Init(NULL));
422 425
423 std::vector<Time> times; 426 std::vector<Time> times;
424 manager.BeginTransaction(); 427 manager.BeginTransaction();
425 AddAllPages(manager, &visit_db, &times); 428 AddAllPages(manager, &visit_db, &times);
426 // "Forget" to commit, it should be autocommittedd for us. 429 // "Forget" to commit, it should be autocommittedd for us.
427 430
428 // We should have matched every page. 431 // We should have matched every page.
429 manager.GetTextMatches(UTF8ToUTF16("FOO"), options, 432 manager.GetTextMatches(ASCIIToUTF16("FOO"), options,
430 &results, &first_time_searched); 433 &results, &first_time_searched);
431 EXPECT_EQ(6U, results.size()); 434 EXPECT_EQ(6U, results.size());
432 } 435 }
433 results.clear(); 436 results.clear();
434 437
435 // Recreate the manager and make sure it finds the written stuff. 438 // Recreate the manager and make sure it finds the written stuff.
436 { 439 {
437 TextDatabaseManager manager(dir_, &visit_db, &visit_db); 440 TextDatabaseManager manager(dir_, &visit_db, &visit_db);
438 ASSERT_TRUE(manager.Init(NULL)); 441 ASSERT_TRUE(manager.Init(NULL));
439 442
440 // We should have matched every page again. 443 // We should have matched every page again.
441 manager.GetTextMatches(UTF8ToUTF16("FOO"), options, 444 manager.GetTextMatches(ASCIIToUTF16("FOO"), options,
442 &results, &first_time_searched); 445 &results, &first_time_searched);
443 EXPECT_EQ(6U, results.size()); 446 EXPECT_EQ(6U, results.size());
444 } 447 }
445 } 448 }
446 449
447 // Tests querying where the maximum number of items is met. 450 // Tests querying where the maximum number of items is met.
448 TEST_F(TextDatabaseManagerTest, QueryMax) { 451 TEST_F(TextDatabaseManagerTest, QueryMax) {
449 ASSERT_TRUE(Init()); 452 ASSERT_TRUE(Init());
450 InMemDB visit_db; 453 InMemDB visit_db;
451 TextDatabaseManager manager(dir_, &visit_db, &visit_db); 454 TextDatabaseManager manager(dir_, &visit_db, &visit_db);
452 ASSERT_TRUE(manager.Init(NULL)); 455 ASSERT_TRUE(manager.Init(NULL));
453 456
454 std::vector<Time> times; 457 std::vector<Time> times;
455 AddAllPages(manager, &visit_db, &times); 458 AddAllPages(manager, &visit_db, &times);
456 459
457 string16 foo = UTF8ToUTF16("FOO"); 460 string16 foo = ASCIIToUTF16("FOO");
458 461
459 QueryOptions options; 462 QueryOptions options;
460 options.begin_time = times[0] - TimeDelta::FromDays(100); 463 options.begin_time = times[0] - TimeDelta::FromDays(100);
461 options.end_time = times[times.size() - 1] + TimeDelta::FromDays(100); 464 options.end_time = times[times.size() - 1] + TimeDelta::FromDays(100);
462 options.max_count = 2; 465 options.max_count = 2;
463 std::vector<TextDatabase::Match> results; 466 std::vector<TextDatabase::Match> results;
464 Time first_time_searched; 467 Time first_time_searched;
465 manager.GetTextMatches(foo, options, &results, &first_time_searched); 468 manager.GetTextMatches(foo, options, &results, &first_time_searched);
466 469
467 // We should have gotten the last two pages as results (the first page is 470 // We should have gotten the last two pages as results (the first page is
(...skipping 18 matching lines...) Expand all
486 // Tests querying backwards in time in chunks. 489 // Tests querying backwards in time in chunks.
487 TEST_F(TextDatabaseManagerTest, QueryBackwards) { 490 TEST_F(TextDatabaseManagerTest, QueryBackwards) {
488 ASSERT_TRUE(Init()); 491 ASSERT_TRUE(Init());
489 InMemDB visit_db; 492 InMemDB visit_db;
490 TextDatabaseManager manager(dir_, &visit_db, &visit_db); 493 TextDatabaseManager manager(dir_, &visit_db, &visit_db);
491 ASSERT_TRUE(manager.Init(NULL)); 494 ASSERT_TRUE(manager.Init(NULL));
492 495
493 std::vector<Time> times; 496 std::vector<Time> times;
494 AddAllPages(manager, &visit_db, &times); 497 AddAllPages(manager, &visit_db, &times);
495 498
496 string16 foo = UTF8ToUTF16("FOO"); 499 string16 foo = ASCIIToUTF16("FOO");
497 500
498 // First do a query for all time, but with a max of 2. This will give us the 501 // First do a query for all time, but with a max of 2. This will give us the
499 // last two results and will tell us where to start searching when we want 502 // last two results and will tell us where to start searching when we want
500 // to go back in time. 503 // to go back in time.
501 QueryOptions options; 504 QueryOptions options;
502 options.begin_time = times[0] - TimeDelta::FromDays(100); 505 options.begin_time = times[0] - TimeDelta::FromDays(100);
503 options.end_time = times[times.size() - 1] + TimeDelta::FromDays(100); 506 options.end_time = times[times.size() - 1] + TimeDelta::FromDays(100);
504 options.max_count = 2; 507 options.max_count = 2;
505 std::vector<TextDatabase::Match> results; 508 std::vector<TextDatabase::Match> results;
506 Time first_time_searched; 509 Time first_time_searched;
(...skipping 20 matching lines...) Expand all
527 EXPECT_TRUE(first_time_searched <= times[0]); 530 EXPECT_TRUE(first_time_searched <= times[0]);
528 EXPECT_TRUE(ResultsHaveURL(results, kURL2)); 531 EXPECT_TRUE(ResultsHaveURL(results, kURL2));
529 EXPECT_TRUE(ResultsHaveURL(results, kURL1)); 532 EXPECT_TRUE(ResultsHaveURL(results, kURL1));
530 533
531 // Try to query some more, there should be no results. 534 // Try to query some more, there should be no results.
532 options.end_time = first_time_searched; 535 options.end_time = first_time_searched;
533 manager.GetTextMatches(foo, options, &results, &first_time_searched); 536 manager.GetTextMatches(foo, options, &results, &first_time_searched);
534 EXPECT_EQ(0U, results.size()); 537 EXPECT_EQ(0U, results.size());
535 } 538 }
536 539
540 TEST_F(TextDatabaseManagerTest, Query) {
541 ASSERT_TRUE(Init());
542
543 QueryOptions options;
544 std::vector<TextDatabase::Match> results;
545 Time first_time_searched;
546
547 InMemDB visit_db;
548
549 TextDatabaseManager manager(dir_, &visit_db, &visit_db);
550 ASSERT_TRUE(manager.Init(NULL));
551
552 std::vector<Time> times;
553 AddAllPages(manager, &visit_db, &times);
554
555 // Try a multi-word query.
556 manager.GetTextMatches(ASCIIToUTF16("FOO drei"), options,
557 &results, &first_time_searched);
558 EXPECT_EQ(1U, results.size());
559 results.clear();
560
561 // Try a quoted query that should match only a single URL.
562 manager.GetTextMatches(ASCIIToUTF16("\"google.de\""),
563 options, &results, &first_time_searched);
564 EXPECT_EQ(1U, results.size());
565 results.clear();
566
567 // Same, but with some special characters.
568 manager.GetTextMatches(ASCIIToUTF16("\"google.de/s?q=mar%10&num=66\""),
569 options, &results, &first_time_searched);
570 EXPECT_EQ(1U, results.size());
571 results.clear();
572
573 // Using separate tokens should match in URL or in body.
574 manager.GetTextMatches(ASCIIToUTF16("google de"), options,
575 &results, &first_time_searched);
576 EXPECT_EQ(2U, results.size());
577 EXPECT_TRUE(ResultsHaveURL(results, kURL4));
578 EXPECT_TRUE(ResultsHaveURL(results, kURL5));
579 results.clear();
580
581 // Try a quoted query that should match the body.
582 manager.GetTextMatches(ASCIIToUTF16("\"Including: punctuation.\""), options,
583 &results, &first_time_searched);
584 EXPECT_EQ(1U, results.size());
585 results.clear();
586
587 // Ensure that punctuation is not ignored in quoted strings.
588 manager.GetTextMatches(ASCIIToUTF16("\"Including punctuation\""), options,
589 &results, &first_time_searched);
590 EXPECT_EQ(0U, results.size());
Scott Hess - ex-Googler 2012/02/10 22:22:32 I don't understand how this one is working. When
Patrick Dubroy 2012/02/11 10:58:39 Weird. It doesn't look like there is any post-quer
Scott Hess - ex-Googler 2012/02/11 17:09:55 Here's what I mean: sqlite> CREATE VIRTUAL TABLE
Patrick Dubroy 2012/02/20 11:00:36 We figured out that this was caused by the fact th
591
592 // Ensure that regex characters don't have special meaning inside quotes.
593 manager.GetTextMatches(ASCIIToUTF16("\"Including* punctuation\""), options,
594 &results, &first_time_searched);
595 EXPECT_EQ(0U, results.size());
596 manager.GetTextMatches(ASCIIToUTF16("\"Including. punctuation\""), options,
597 &results, &first_time_searched);
598 EXPECT_EQ(0U, results.size());
599 manager.GetTextMatches(ASCIIToUTF16("\"Including_ punctuation\""), options,
600 &results, &first_time_searched);
601 EXPECT_EQ(0U, results.size());
602 }
603
537 } // namespace history 604 } // namespace history
OLDNEW
« chrome/browser/history/query_parser.cc ('K') | « chrome/browser/history/query_parser_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698