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

Side by Side Diff: chrome/browser/autocomplete/history_quick_provider_unittest.cc

Issue 6652008: Implemented substring matching within page titles. Fixed bug where URL was be... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 "chrome/browser/autocomplete/history_quick_provider.h" 5 #include "chrome/browser/autocomplete/history_quick_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/autocomplete/autocomplete_match.h" 16 #include "chrome/browser/autocomplete/autocomplete_match.h"
17 #include "chrome/browser/history/history.h" 17 #include "chrome/browser/history/history.h"
18 #include "chrome/browser/history/in_memory_url_index.h"
18 #include "chrome/browser/history/url_database.h" 19 #include "chrome/browser/history/url_database.h"
19 #include "chrome/browser/prefs/pref_service.h" 20 #include "chrome/browser/prefs/pref_service.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
21 #include "chrome/test/testing_browser_process.h" 22 #include "chrome/test/testing_browser_process.h"
22 #include "chrome/test/testing_browser_process_test.h" 23 #include "chrome/test/testing_browser_process_test.h"
23 #include "chrome/test/testing_profile.h" 24 #include "chrome/test/testing_profile.h"
24 #include "content/browser/browser_thread.h" 25 #include "content/browser/browser_thread.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
27 using base::Time; 28 using base::Time;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 string16 text(ASCIIToUTF16("startest")); 232 string16 text(ASCIIToUTF16("startest"));
232 std::vector<std::string> expected_urls; 233 std::vector<std::string> expected_urls;
233 expected_urls.push_back("http://startest.com/y/a"); 234 expected_urls.push_back("http://startest.com/y/a");
234 expected_urls.push_back("http://startest.com/y/b"); 235 expected_urls.push_back("http://startest.com/y/b");
235 expected_urls.push_back("http://startest.com/x/c"); 236 expected_urls.push_back("http://startest.com/x/c");
236 expected_urls.push_back("http://startest.com/x/d"); 237 expected_urls.push_back("http://startest.com/x/d");
237 expected_urls.push_back("http://startest.com/y/e"); 238 expected_urls.push_back("http://startest.com/y/e");
238 expected_urls.push_back("http://startest.com/y/f"); 239 expected_urls.push_back("http://startest.com/y/f");
239 RunTest(text, expected_urls, "http://startest.com/y/a"); 240 RunTest(text, expected_urls, "http://startest.com/y/a");
240 } 241 }
242
243 TEST_F(HistoryQuickProviderTest, Spans) {
244 // Test SpansFromTermMatch
245 history::TermMatches matches_a;
246 // Simulates matches: '.xx.xxx..xx...xxxxx..' which will test no match at
247 // either beginning or end as well as adjacent matches.
248 matches_a.push_back(history::TermMatch(1, 1, 2));
249 matches_a.push_back(history::TermMatch(2, 4, 3));
250 matches_a.push_back(history::TermMatch(3, 9, 1));
251 matches_a.push_back(history::TermMatch(3, 10, 1));
252 matches_a.push_back(history::TermMatch(4, 14, 5));
253 ACMatchClassifications spans_a =
254 HistoryQuickProvider::SpansFromTermMatch(matches_a, 20, 0);
255 // ACMatch spans should be: 'NM-NM---N-M-N--M----N-'
256 ASSERT_EQ(9U, spans_a.size());
257 EXPECT_EQ(0U, spans_a[0].offset);
258 EXPECT_EQ(ACMatchClassification::NONE, spans_a[0].style);
259 EXPECT_EQ(1U, spans_a[1].offset);
260 EXPECT_EQ(ACMatchClassification::MATCH, spans_a[1].style);
261 EXPECT_EQ(3U, spans_a[2].offset);
262 EXPECT_EQ(ACMatchClassification::NONE, spans_a[2].style);
263 EXPECT_EQ(4U, spans_a[3].offset);
264 EXPECT_EQ(ACMatchClassification::MATCH, spans_a[3].style);
265 EXPECT_EQ(7U, spans_a[4].offset);
266 EXPECT_EQ(ACMatchClassification::NONE, spans_a[4].style);
267 EXPECT_EQ(9U, spans_a[5].offset);
268 EXPECT_EQ(ACMatchClassification::MATCH, spans_a[5].style);
269 EXPECT_EQ(11U, spans_a[6].offset);
270 EXPECT_EQ(ACMatchClassification::NONE, spans_a[6].style);
271 EXPECT_EQ(14U, spans_a[7].offset);
272 EXPECT_EQ(ACMatchClassification::MATCH, spans_a[7].style);
273 EXPECT_EQ(19U, spans_a[8].offset);
274 EXPECT_EQ(ACMatchClassification::NONE, spans_a[8].style);
275 // Simulates matches: 'xx.xx' which will test matches at both beginning an
276 // end.
277 history::TermMatches matches_b;
278 matches_b.push_back(history::TermMatch(1, 0, 2));
279 matches_b.push_back(history::TermMatch(2, 3, 2));
280 ACMatchClassifications spans_b =
281 HistoryQuickProvider::SpansFromTermMatch(matches_b, 5, 0);
282 // ACMatch spans should be: 'M-NM-'
283 ASSERT_EQ(3U, spans_b.size());
284 EXPECT_EQ(0U, spans_b[0].offset);
285 EXPECT_EQ(ACMatchClassification::MATCH, spans_b[0].style);
286 EXPECT_EQ(2U, spans_b[1].offset);
287 EXPECT_EQ(ACMatchClassification::NONE, spans_b[1].style);
288 EXPECT_EQ(3U, spans_b[2].offset);
289 EXPECT_EQ(ACMatchClassification::MATCH, spans_b[2].style);
290 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_quick_provider.cc ('k') | chrome/browser/history/in_memory_url_index.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698