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 "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> |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 {"http://abcxyzdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, | 83 {"http://abcxyzdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, |
84 {"http://xyzabcdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, | 84 {"http://xyzabcdefghijklmnopqrstuvw.com/a", "", 3, 1, 0}, |
85 {"http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice", | 85 {"http://cda.com/Dogs%20Cats%20Gorillas%20Sea%20Slugs%20and%20Mice", |
86 "Dogs & Cats & Mice & Other Animals", 1, 1, 0}, | 86 "Dogs & Cats & Mice & Other Animals", 1, 1, 0}, |
87 {"https://monkeytrap.org/", "", 3, 1, 0}, | 87 {"https://monkeytrap.org/", "", 3, 1, 0}, |
88 {"http://popularsitewithpathonly.com/moo", | 88 {"http://popularsitewithpathonly.com/moo", |
89 "popularsitewithpathonly.com/moo", 50, 50, 0}, | 89 "popularsitewithpathonly.com/moo", 50, 50, 0}, |
90 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0}, | 90 {"http://popularsitewithroot.com/", "popularsitewithroot.com", 50, 50, 0}, |
91 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0}, | 91 {"http://testsearch.com/?q=thequery", "Test Search Engine", 10, 10, 0}, |
92 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0}, | 92 {"http://testsearch.com/", "Test Search Engine", 9, 9, 0}, |
93 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, 0} | 93 {"http://anotherengine.com/?q=thequery", "Another Search Engine", 8, 8, 0}, |
94 // The encoded stuff between /wiki/ and the # is 第二次世界大戦 | |
95 {"http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7%95" | |
96 "%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3." | |
97 "83.A6.E4.BD.93.E5.88.B6", "Title Unimportant", 2, 2, 0} | |
94 }; | 98 }; |
95 | 99 |
96 class HistoryQuickProviderTest : public testing::Test, | 100 class HistoryQuickProviderTest : public testing::Test, |
97 public AutocompleteProviderListener { | 101 public AutocompleteProviderListener { |
98 public: | 102 public: |
99 HistoryQuickProviderTest() | 103 HistoryQuickProviderTest() |
100 : ui_thread_(BrowserThread::UI, &message_loop_), | 104 : ui_thread_(BrowserThread::UI, &message_loop_), |
101 file_thread_(BrowserThread::FILE, &message_loop_) {} | 105 file_thread_(BrowserThread::FILE, &message_loop_) {} |
102 | 106 |
103 // AutocompleteProviderListener: | 107 // AutocompleteProviderListener: |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
351 } | 355 } |
352 | 356 |
353 TEST_F(HistoryQuickProviderTest, EncodingMatch) { | 357 TEST_F(HistoryQuickProviderTest, EncodingMatch) { |
354 std::vector<std::string> expected_urls; | 358 std::vector<std::string> expected_urls; |
355 expected_urls.push_back("http://spaces.com/path%20with%20spaces/foo.html"); | 359 expected_urls.push_back("http://spaces.com/path%20with%20spaces/foo.html"); |
356 RunTest(ASCIIToUTF16("path with spaces"), false, expected_urls, false, | 360 RunTest(ASCIIToUTF16("path with spaces"), false, expected_urls, false, |
357 ASCIIToUTF16("spaces.com/path with spaces/foo.html"), | 361 ASCIIToUTF16("spaces.com/path with spaces/foo.html"), |
358 base::string16()); | 362 base::string16()); |
359 } | 363 } |
360 | 364 |
365 TEST_F(HistoryQuickProviderTest, ContentsClass) { | |
366 std::vector<std::string> expected_urls; | |
367 expected_urls.push_back( | |
368 "http://ja.wikipedia.org/wiki/%E7%AC%AC%E4%BA%8C%E6%AC%A1%E4%B8%96%E7" | |
369 "%95%8C%E5%A4%A7%E6%88%A6#.E3.83.B4.E3.82.A7.E3.83.AB.E3.82.B5.E3.82." | |
370 "A4.E3.83.A6.E4.BD.93.E5.88.B6"); | |
371 RunTest(base::UTF8ToUTF16("第二 e3"), false, expected_urls, false, | |
372 base::UTF8ToUTF16("ja.wikipedia.org/wiki/第二次世界大戦#.E3.83.B4.E3." | |
373 "82.A7.E3.83.AB.E3.82.B5.E3.82.A4.E3.83.A6.E4.BD." | |
374 "93.E5.88.B6"), | |
375 base::string16()); | |
376 ac_matches_[0].Validate(); | |
377 // Verify that contents_class divides the string in the right places. | |
378 // [22, 24) is the "第二". All the other pairs are the "e3". | |
379 ACMatchClassifications contents_class(ac_matches_[0].contents_class); | |
380 size_t expected_offsets[] = { 0, 22, 24, 31, 33, 40, 42, 49, 51, 58, 60, 67, | |
381 69, 76, 78 }; | |
382 // ScoredHistoryMatch may not highlight all the occurrences of these terms | |
383 // because it only highlights terms at word breaks, and it only stores word | |
384 // breaks up to some specified number of characters (50 at the time of this | |
385 // comment). This test is written flexibly so it still will pass if we | |
386 // increase that number in the future. Regardless, we require the first | |
387 // five offsets to be correct--in this example tthese cover at least one | |
Peter Kasting
2014/04/24 21:00:52
Nit: tthese -> these
Mark P
2014/04/24 23:05:17
Done.
| |
388 // occurrence of each term. | |
389 EXPECT_GE(arraysize(expected_offsets), contents_class.size()); | |
Peter Kasting
2014/04/24 21:00:52
I think you want to reverse the ordering on this E
Mark P
2014/04/24 23:05:17
Done.
| |
390 EXPECT_GE(contents_class.size(), 5u); | |
391 for (size_t i = 0; i < contents_class.size(); ++i) | |
392 EXPECT_EQ(expected_offsets[i], contents_class[i].offset); | |
393 } | |
394 | |
361 TEST_F(HistoryQuickProviderTest, VisitCountMatches) { | 395 TEST_F(HistoryQuickProviderTest, VisitCountMatches) { |
362 std::vector<std::string> expected_urls; | 396 std::vector<std::string> expected_urls; |
363 expected_urls.push_back("http://visitedest.com/y/a"); | 397 expected_urls.push_back("http://visitedest.com/y/a"); |
364 expected_urls.push_back("http://visitedest.com/y/b"); | 398 expected_urls.push_back("http://visitedest.com/y/b"); |
365 expected_urls.push_back("http://visitedest.com/x/c"); | 399 expected_urls.push_back("http://visitedest.com/x/c"); |
366 RunTest(ASCIIToUTF16("visitedest"), false, expected_urls, true, | 400 RunTest(ASCIIToUTF16("visitedest"), false, expected_urls, true, |
367 ASCIIToUTF16("visitedest.com/y/a"), | 401 ASCIIToUTF16("visitedest.com/y/a"), |
368 ASCIIToUTF16(".com/y/a")); | 402 ASCIIToUTF16(".com/y/a")); |
369 } | 403 } |
370 | 404 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
669 | 703 |
670 TEST_F(HQPOrderingTest, TEAMatch) { | 704 TEST_F(HQPOrderingTest, TEAMatch) { |
671 std::vector<std::string> expected_urls; | 705 std::vector<std::string> expected_urls; |
672 expected_urls.push_back("http://www.teamliquid.net/"); | 706 expected_urls.push_back("http://www.teamliquid.net/"); |
673 expected_urls.push_back("http://www.teamliquid.net/tlpd"); | 707 expected_urls.push_back("http://www.teamliquid.net/tlpd"); |
674 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); | 708 expected_urls.push_back("http://www.teamliquid.net/tlpd/korean/players"); |
675 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, | 709 RunTest(ASCIIToUTF16("tea"), false, expected_urls, true, |
676 ASCIIToUTF16("www.teamliquid.net"), | 710 ASCIIToUTF16("www.teamliquid.net"), |
677 ASCIIToUTF16("mliquid.net")); | 711 ASCIIToUTF16("mliquid.net")); |
678 } | 712 } |
OLD | NEW |