OLD | NEW |
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 Loading... |
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", | 104 "83.A6.E4.BD.93.E5.88.B6", "Title Unimportant", 2, 2, 0} |
105 "Title Unimportant", 2, 2, 0}, | 105 }; |
106 {"https://twitter.com/fungoodtimes", "relatable!", 1, 1, 0}}; | |
107 | 106 |
108 // Waits for OnURLsDeletedNotification and when run quits the supplied run loop. | 107 // Waits for OnURLsDeletedNotification and when run quits the supplied run loop. |
109 class WaitForURLsDeletedObserver : public history::HistoryServiceObserver { | 108 class WaitForURLsDeletedObserver : public history::HistoryServiceObserver { |
110 public: | 109 public: |
111 explicit WaitForURLsDeletedObserver(base::RunLoop* runner); | 110 explicit WaitForURLsDeletedObserver(base::RunLoop* runner); |
112 ~WaitForURLsDeletedObserver() override; | 111 ~WaitForURLsDeletedObserver() override; |
113 | 112 |
114 private: | 113 private: |
115 // history::HistoryServiceObserver: | 114 // history::HistoryServiceObserver: |
116 void OnURLsDeleted(history::HistoryService* service, | 115 void OnURLsDeleted(history::HistoryService* service, |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 std::vector<std::string> expected_urls; | 489 std::vector<std::string> expected_urls; |
491 expected_urls.push_back("http://slashdot.org/favorite_page.html"); | 490 expected_urls.push_back("http://slashdot.org/favorite_page.html"); |
492 // With cursor after "slash", we should retrieve the desired result but it | 491 // With cursor after "slash", we should retrieve the desired result but it |
493 // should not be allowed to be the default match. | 492 // should not be allowed to be the default match. |
494 RunTestWithCursor(ASCIIToUTF16("slashfavorite_page.html"), 5, false, | 493 RunTestWithCursor(ASCIIToUTF16("slashfavorite_page.html"), 5, false, |
495 expected_urls, false, | 494 expected_urls, false, |
496 ASCIIToUTF16("slashdot.org/favorite_page.html"), | 495 ASCIIToUTF16("slashdot.org/favorite_page.html"), |
497 base::string16()); | 496 base::string16()); |
498 } | 497 } |
499 | 498 |
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 | |
510 TEST_F(HistoryQuickProviderTest, WordBoundariesWithPunctuationMatch) { | 499 TEST_F(HistoryQuickProviderTest, WordBoundariesWithPunctuationMatch) { |
511 std::vector<std::string> expected_urls; | 500 std::vector<std::string> expected_urls; |
512 expected_urls.push_back("http://popularsitewithpathonly.com/moo"); | 501 expected_urls.push_back("http://popularsitewithpathonly.com/moo"); |
513 RunTest(ASCIIToUTF16("/moo"), false, expected_urls, false, | 502 RunTest(ASCIIToUTF16("/moo"), false, expected_urls, false, |
514 ASCIIToUTF16("popularsitewithpathonly.com/moo"), base::string16()); | 503 ASCIIToUTF16("popularsitewithpathonly.com/moo"), base::string16()); |
515 } | 504 } |
516 | 505 |
517 TEST_F(HistoryQuickProviderTest, MultiTermTitleMatch) { | 506 TEST_F(HistoryQuickProviderTest, MultiTermTitleMatch) { |
518 std::vector<std::string> expected_urls; | 507 std::vector<std::string> expected_urls; |
519 expected_urls.push_back( | 508 expected_urls.push_back( |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 | 887 |
899 TEST_F(HQPOrderingTest, TEAMatch) { | 888 TEST_F(HQPOrderingTest, TEAMatch) { |
900 std::vector<std::string> expected_urls; | 889 std::vector<std::string> expected_urls; |
901 expected_urls.push_back("http://www.teamliquid.net/"); | 890 expected_urls.push_back("http://www.teamliquid.net/"); |
902 expected_urls.push_back("http://www.teamliquid.net/tlpd"); | 891 expected_urls.push_back("http://www.teamliquid.net/tlpd"); |
903 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); | 892 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); |
904 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, | 893 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, |
905 ASCIIToUTF16("www.teamliquid.net"), | 894 ASCIIToUTF16("www.teamliquid.net"), |
906 ASCIIToUTF16("mliquid.net")); | 895 ASCIIToUTF16("mliquid.net")); |
907 } | 896 } |
OLD | NEW |