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

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

Issue 255423002: Omnibox: Highlight Matches in URLs Properly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix OffsetsFromTermMatches test Created 6 years, 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/format_macros.h" 13 #include "base/format_macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/prefs/pref_service.h" 16 #include "base/prefs/pref_service.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "chrome/browser/autocomplete/autocomplete_match.h"
19 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" 20 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
20 #include "chrome/browser/autocomplete/autocomplete_result.h" 21 #include "chrome/browser/autocomplete/autocomplete_result.h"
21 #include "chrome/browser/autocomplete/history_url_provider.h" 22 #include "chrome/browser/autocomplete/history_url_provider.h"
22 #include "chrome/browser/bookmarks/bookmark_test_helpers.h" 23 #include "chrome/browser/bookmarks/bookmark_test_helpers.h"
23 #include "chrome/browser/history/history_backend.h" 24 #include "chrome/browser/history/history_backend.h"
24 #include "chrome/browser/history/history_database.h" 25 #include "chrome/browser/history/history_database.h"
25 #include "chrome/browser/history/history_service.h" 26 #include "chrome/browser/history/history_service.h"
26 #include "chrome/browser/history/history_service_factory.h" 27 #include "chrome/browser/history/history_service_factory.h"
27 #include "chrome/browser/history/in_memory_url_index.h" 28 #include "chrome/browser/history/in_memory_url_index.h"
28 #include "chrome/browser/history/url_database.h" 29 #include "chrome/browser/history/url_database.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 {"http://abcxyzdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, 84 {"http://abcxyzdefghijklmnopqrstuvw.com/a", "", 3, 1, 0},
84 {"http://xyzabcdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, 85 {"http://xyzabcdefghijklmnopqrstuvw.com/a", "", 3, 1, 0},
85 {"http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice", 86 {"http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice",
86 "Dogs & Cats & Mice & Other Animals", 1, 1, 0}, 87 "Dogs & Cats & Mice & Other Animals", 1, 1, 0},
87 {"https://monkeytrap.org/", "", 3, 1, 0}, 88 {"https://monkeytrap.org/", "", 3, 1, 0},
88 {"http://popularsitewithpathonly.com/moo", 89 {"http://popularsitewithpathonly.com/moo",
89 "popularsitewithpathonly.com/moo", 50, 50, 0}, 90 "popularsitewithpathonly.com/moo", 50, 50, 0},
90 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0}, 91 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0},
91 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0}, 92 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0},
92 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0}, 93 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0},
93 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, 0} 94 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, 0},
95 // The encoded stuff between /wiki/ and the # is 第二次世界大戦
96 {"http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7%95"
97 "%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3."
98 "83.A6.E4.BD.93.E5.88.B6", "Title Unimportant", 2, 2, 0}
94 }; 99 };
95 100
96 class HistoryQuickProviderTest : public testing::Test, 101 class HistoryQuickProviderTest : public testing::Test,
97 public AutocompleteProviderListener { 102 public AutocompleteProviderListener {
98 public: 103 public:
99 HistoryQuickProviderTest() 104 HistoryQuickProviderTest()
100 : ui_thread_(BrowserThread::UI, &message_loop_), 105 : ui_thread_(BrowserThread::UI, &message_loop_),
101 file_thread_(BrowserThread::FILE, &message_loop_) {} 106 file_thread_(BrowserThread::FILE, &message_loop_) {}
102 107
103 // AutocompleteProviderListener: 108 // AutocompleteProviderListener:
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 } 356 }
352 357
353 TEST_F(HistoryQuickProviderTest, EncodingMatch) { 358 TEST_F(HistoryQuickProviderTest, EncodingMatch) {
354 std::vector<std::string> expected_urls; 359 std::vector<std::string> expected_urls;
355 expected_urls.push_back("http://spaces.com/path%20with%20spaces/foo.html"); 360 expected_urls.push_back("http://spaces.com/path%20with%20spaces/foo.html");
356 RunTest(ASCIIToUTF16("path with spaces"), false, expected_urls, false, 361 RunTest(ASCIIToUTF16("path with spaces"), false, expected_urls, false,
357 ASCIIToUTF16("spaces.com/path with spaces/foo.html"), 362 ASCIIToUTF16("spaces.com/path with spaces/foo.html"),
358 base::string16()); 363 base::string16());
359 } 364 }
360 365
366 TEST_F(HistoryQuickProviderTest, ContentsClass) {
367 std::vector<std::string> expected_urls;
368 expected_urls.push_back(
369 "http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7"
370 "%95%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82."
371 "A4.E3.83.A6.E4.BD.93.E5.88.B6");
372 RunTest(base::UTF8ToUTF16("第二 e3"), false, expected_urls, false,
373 base::UTF8ToUTF16("ja.wikipedia.org/wiki/第二次世界大戦#.E3.83.B4.E3."
374 "82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3.83.A6.E4.BD."
375 "93.E5.88.B6"),
376 base::string16());
377 #ifndef NDEBUG
378 ac_matches_[0].Validate();
379 #endif
380 // Verify that contents_class divides the string in the right places.
381 // [22, 24) is the "第二". All the other pairs are the "e3".
382 ACMatchClassifications contents_class(ac_matches_[0].contents_class);
383 size_t expected_offsets[] = { 0, 22, 24, 31, 33, 40, 42, 49, 51, 58, 60, 67,
384 69, 76, 78 };
385 // ScoredHistoryMatch may not highlight all the occurrences of these terms
386 // because it only highlights terms at word breaks, and it only stores word
387 // breaks up to some specified number of characters (50 at the time of this
388 // comment). This test is written flexibly so it still will pass if we
389 // increase that number in the future. Regardless, we require the first
390 // five offsets to be correct--in this example these cover at least one
391 // occurrence of each term.
392 EXPECT_LE(contents_class.size(), arraysize(expected_offsets));
393 EXPECT_GE(contents_class.size(), 5u);
394 for (size_t i = 0; i < contents_class.size(); ++i)
395 EXPECT_EQ(expected_offsets[i], contents_class[i].offset);
396 }
397
361 TEST_F(HistoryQuickProviderTest, VisitCountMatches) { 398 TEST_F(HistoryQuickProviderTest, VisitCountMatches) {
362 std::vector<std::string> expected_urls; 399 std::vector<std::string> expected_urls;
363 expected_urls.push_back("http://visitedest.com/y/a"); 400 expected_urls.push_back("http://visitedest.com/y/a");
364 expected_urls.push_back("http://visitedest.com/y/b"); 401 expected_urls.push_back("http://visitedest.com/y/b");
365 expected_urls.push_back("http://visitedest.com/x/c"); 402 expected_urls.push_back("http://visitedest.com/x/c");
366 RunTest(ASCIIToUTF16("visitedest"), false, expected_urls, true, 403 RunTest(ASCIIToUTF16("visitedest"), false, expected_urls, true,
367 ASCIIToUTF16("visitedest.com/y/a"), 404 ASCIIToUTF16("visitedest.com/y/a"),
368 ASCIIToUTF16(".com/y/a")); 405 ASCIIToUTF16(".com/y/a"));
369 } 406 }
370 407
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 706
670 TEST_F(HQPOrderingTest, TEAMatch) { 707 TEST_F(HQPOrderingTest, TEAMatch) {
671 std::vector<std::string> expected_urls; 708 std::vector<std::string> expected_urls;
672 expected_urls.push_back("http://www.teamliquid.net/"); 709 expected_urls.push_back("http://www.teamliquid.net/");
673 expected_urls.push_back("http://www.teamliquid.net/tlpd"); 710 expected_urls.push_back("http://www.teamliquid.net/tlpd");
674 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); 711 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players");
675 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, 712 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true,
676 ASCIIToUTF16("www.teamliquid.net"), 713 ASCIIToUTF16("www.teamliquid.net"),
677 ASCIIToUTF16("mliquid.net")); 714 ASCIIToUTF16("mliquid.net"));
678 } 715 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_quick_provider.cc ('k') | chrome/browser/bookmarks/bookmark_index.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698