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

Side by Side Diff: components/omnibox/browser/history_quick_provider_unittest.cc

Issue 2364553004: Updated and refactored URLIndexPrivateData::HistoryItemsForTerms to handle searching the history fo… (Closed)
Patch Set: Fixed bug to properly increment post_filter_item_count_. Created 4 years, 2 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
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 "components/omnibox/browser/history_quick_provider.h" 5 #include "components/omnibox/browser/history_quick_provider.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <functional> 10 #include <functional>
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 namespace { 51 namespace {
52 52
53 struct TestURLInfo { 53 struct TestURLInfo {
54 std::string url; 54 std::string url;
55 std::string title; 55 std::string title;
56 int visit_count; 56 int visit_count;
57 int typed_count; 57 int typed_count;
58 int days_from_now; 58 int days_from_now;
59 } quick_test_db[] = { 59 } quick_test_db[] = {
60 {"http://www.google.com/", "Google", 3, 3, 0}, 60 {"http://www.google.com/", "Google", 3, 3, 0},
61 {"http://slashdot.org/favorite_page.html", "Favorite page", 200, 100, 0}, 61 {"http://slashdot.org/favorite_page.html", "Favorite page", 200, 100, 0},
62 {"http://kerneltrap.org/not_very_popular.html", "Less popular", 4, 0, 0}, 62 {"http://kerneltrap.org/not_very_popular.html", "Less popular", 4, 0, 0},
63 {"http://freshmeat.net/unpopular.html", "Unpopular", 1, 1, 0}, 63 {"http://freshmeat.net/unpopular.html", "Unpopular", 1, 1, 0},
64 {"http://news.google.com/?ned=us&topic=n", "Google News - U.S.", 2, 2, 0}, 64 {"http://news.google.com/?ned=us&topic=n", "Google News - U.S.", 2, 2, 0},
65 {"http://news.google.com/", "Google News", 1, 1, 0}, 65 {"http://news.google.com/", "Google News", 1, 1, 0},
66 {"http://foo.com/", "Dir", 200, 100, 0}, 66 {"http://foo.com/", "Dir", 200, 100, 0},
67 {"http://foo.com/dir/", "Dir", 2, 1, 10}, 67 {"http://foo.com/dir/", "Dir", 2, 1, 10},
68 {"http://foo.com/dir/another/", "Dir", 10, 5, 0}, 68 {"http://foo.com/dir/another/", "Dir", 10, 5, 0},
69 {"http://foo.com/dir/another/again/", "Dir", 5, 1, 0}, 69 {"http://foo.com/dir/another/again/", "Dir", 5, 1, 0},
70 {"http://foo.com/dir/another/again/myfile.html", "File", 3, 1, 0}, 70 {"http://foo.com/dir/another/again/myfile.html", "File", 3, 1, 0},
71 {"http://visitedest.com/y/a", "VA", 10, 1, 20}, 71 {"http://visitedest.com/y/a", "VA", 10, 1, 20},
72 {"http://visitedest.com/y/b", "VB", 9, 1, 20}, 72 {"http://visitedest.com/y/b", "VB", 9, 1, 20},
73 {"http://visitedest.com/x/c", "VC", 8, 1, 20}, 73 {"http://visitedest.com/x/c", "VC", 8, 1, 20},
74 {"http://visitedest.com/x/d", "VD", 7, 1, 20}, 74 {"http://visitedest.com/x/d", "VD", 7, 1, 20},
75 {"http://visitedest.com/y/e", "VE", 6, 1, 20}, 75 {"http://visitedest.com/y/e", "VE", 6, 1, 20},
76 {"http://typeredest.com/y/a", "TA", 5, 5, 0}, 76 {"http://typeredest.com/y/a", "TA", 5, 5, 0},
77 {"http://typeredest.com/y/b", "TB", 5, 4, 0}, 77 {"http://typeredest.com/y/b", "TB", 5, 4, 0},
78 {"http://typeredest.com/x/c", "TC", 5, 3, 0}, 78 {"http://typeredest.com/x/c", "TC", 5, 3, 0},
79 {"http://typeredest.com/x/d", "TD", 5, 2, 0}, 79 {"http://typeredest.com/x/d", "TD", 5, 2, 0},
80 {"http://typeredest.com/y/e", "TE", 5, 1, 0}, 80 {"http://typeredest.com/y/e", "TE", 5, 1, 0},
81 {"http://daysagoest.com/y/a", "DA", 1, 1, 0}, 81 {"http://daysagoest.com/y/a", "DA", 1, 1, 0},
82 {"http://daysagoest.com/y/b", "DB", 1, 1, 1}, 82 {"http://daysagoest.com/y/b", "DB", 1, 1, 1},
83 {"http://daysagoest.com/x/c", "DC", 1, 1, 2}, 83 {"http://daysagoest.com/x/c", "DC", 1, 1, 2},
84 {"http://daysagoest.com/x/d", "DD", 1, 1, 3}, 84 {"http://daysagoest.com/x/d", "DD", 1, 1, 3},
85 {"http://daysagoest.com/y/e", "DE", 1, 1, 4}, 85 {"http://daysagoest.com/y/e", "DE", 1, 1, 4},
86 {"http://abcdefghixyzjklmnopqrstuvw.com/a", "", 3, 1, 0}, 86 {"http://abcdefghixyzjklmnopqrstuvw.com/a", "", 3, 1, 0},
87 {"http://spaces.com/path%20with%20spaces/foo.html", "Spaces", 2, 2, 0}, 87 {"http://spaces.com/path%20with%20spaces/foo.html", "Spaces", 2, 2, 0},
88 {"http://abcdefghijklxyzmnopqrstuvw.com/a", "", 3, 1, 0}, 88 {"http://abcdefghijklxyzmnopqrstuvw.com/a", "", 3, 1, 0},
89 {"http://abcdefxyzghijklmnopqrstuvw.com/a", "", 3, 1, 0}, 89 {"http://abcdefxyzghijklmnopqrstuvw.com/a", "", 3, 1, 0},
90 {"http://abcxyzdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, 90 {"http://abcxyzdefghijklmnopqrstuvw.com/a", "", 3, 1, 0},
91 {"http://xyzabcdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, 91 {"http://xyzabcdefghijklmnopqrstuvw.com/a", "", 3, 1, 0},
92 {"http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice", 92 {"http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice",
93 "Dogs & Cats & Mice & Other Animals", 1, 1, 0}, 93 "Dogs & Cats & Mice & Other Animals", 1, 1, 0},
94 {"https://monkeytrap.org/", "", 3, 1, 0}, 94 {"https://monkeytrap.org/", "", 3, 1, 0},
95 {"http://popularsitewithpathonly.com/moo", 95 {"http://popularsitewithpathonly.com/moo",
96 "popularsitewithpathonly.com/moo", 50, 50, 0}, 96 "popularsitewithpathonly.com/moo", 50, 50, 0},
97 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0}, 97 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0},
98 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0}, 98 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0},
99 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0}, 99 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0},
100 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, 0}, 100 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, 0},
101 // The encoded stuff between /wiki/ and the # is 第二次世界大戦 101 // The encoded stuff between /wiki/ and the # is 第二次世界大戦
102 {"http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7%95" 102 {"http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7%95"
103 "%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3." 103 "%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3."
104 "83.A6.E4.BD.93.E5.88.B6", "Title Unimportant", 2, 2, 0} 104 "83.A6.E4.BD.93.E5.88.B6",
105 }; 105 "Title Unimportant", 2, 2, 0},
106 {"https://twitter.com/fungoodtimes", "relatable!", 1, 1, 0}};
106 107
107 // Waits for OnURLsDeletedNotification and when run quits the supplied run loop. 108 // Waits for OnURLsDeletedNotification and when run quits the supplied run loop.
108 class WaitForURLsDeletedObserver : public history::HistoryServiceObserver { 109 class WaitForURLsDeletedObserver : public history::HistoryServiceObserver {
109 public: 110 public:
110 explicit WaitForURLsDeletedObserver(base::RunLoop* runner); 111 explicit WaitForURLsDeletedObserver(base::RunLoop* runner);
111 ~WaitForURLsDeletedObserver() override; 112 ~WaitForURLsDeletedObserver() override;
112 113
113 private: 114 private:
114 // history::HistoryServiceObserver: 115 // history::HistoryServiceObserver:
115 void OnURLsDeleted(history::HistoryService* service, 116 void OnURLsDeleted(history::HistoryService* service,
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 std::vector<std::string> expected_urls; 490 std::vector<std::string> expected_urls;
490 expected_urls.push_back("http://slashdot.org/favorite_page.html"); 491 expected_urls.push_back("http://slashdot.org/favorite_page.html");
491 // With cursor after "slash", we should retrieve the desired result but it 492 // With cursor after "slash", we should retrieve the desired result but it
492 // should not be allowed to be the default match. 493 // should not be allowed to be the default match.
493 RunTestWithCursor(ASCIIToUTF16("slashfavorite_page.html"), 5, false, 494 RunTestWithCursor(ASCIIToUTF16("slashfavorite_page.html"), 5, false,
494 expected_urls, false, 495 expected_urls, false,
495 ASCIIToUTF16("slashdot.org/favorite_page.html"), 496 ASCIIToUTF16("slashdot.org/favorite_page.html"),
496 base::string16()); 497 base::string16());
497 } 498 }
498 499
500 TEST_F(HistoryQuickProviderTest, MatchWithAndWithoutCursorWordBreak) {
501 std::vector<std::string> expected_urls;
502 expected_urls.push_back("https://twitter.com/fungoodtimes");
503 // With cursor after "good", we should retrieve the desired result but it
504 // should not be allowed to be the default match.
505 RunTestWithCursor(ASCIIToUTF16("fungoodtimes"), 7, false, expected_urls,
506 false, ASCIIToUTF16("https://twitter.com/fungoodtimes"),
507 base::string16());
508 }
509
499 TEST_F(HistoryQuickProviderTest, WordBoundariesWithPunctuationMatch) { 510 TEST_F(HistoryQuickProviderTest, WordBoundariesWithPunctuationMatch) {
500 std::vector<std::string> expected_urls; 511 std::vector<std::string> expected_urls;
501 expected_urls.push_back("http://popularsitewithpathonly.com/moo"); 512 expected_urls.push_back("http://popularsitewithpathonly.com/moo");
502 RunTest(ASCIIToUTF16("/moo"), false, expected_urls, false, 513 RunTest(ASCIIToUTF16("/moo"), false, expected_urls, false,
503 ASCIIToUTF16("popularsitewithpathonly.com/moo"), base::string16()); 514 ASCIIToUTF16("popularsitewithpathonly.com/moo"), base::string16());
504 } 515 }
505 516
506 TEST_F(HistoryQuickProviderTest, MultiTermTitleMatch) { 517 TEST_F(HistoryQuickProviderTest, MultiTermTitleMatch) {
507 std::vector<std::string> expected_urls; 518 std::vector<std::string> expected_urls;
508 expected_urls.push_back( 519 expected_urls.push_back(
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 898
888 TEST_F(HQPOrderingTest, TEAMatch) { 899 TEST_F(HQPOrderingTest, TEAMatch) {
889 std::vector<std::string> expected_urls; 900 std::vector<std::string> expected_urls;
890 expected_urls.push_back("http://www.teamliquid.net/"); 901 expected_urls.push_back("http://www.teamliquid.net/");
891 expected_urls.push_back("http://www.teamliquid.net/tlpd"); 902 expected_urls.push_back("http://www.teamliquid.net/tlpd");
892 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); 903 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players");
893 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, 904 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true,
894 ASCIIToUTF16("www.teamliquid.net"), 905 ASCIIToUTF16("www.teamliquid.net"),
895 ASCIIToUTF16("mliquid.net")); 906 ASCIIToUTF16("mliquid.net"));
896 } 907 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698