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

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

Issue 109013006: Update some uses of UTF conversions in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 12 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_url_provider.h" 5 #include "chrome/browser/autocomplete/history_url_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/search_engines/template_url.h" 21 #include "chrome/browser/search_engines/template_url.h"
22 #include "chrome/browser/search_engines/template_url_service.h" 22 #include "chrome/browser/search_engines/template_url_service.h"
23 #include "chrome/browser/search_engines/template_url_service_factory.h" 23 #include "chrome/browser/search_engines/template_url_service_factory.h"
24 #include "chrome/common/net/url_fixer_upper.h" 24 #include "chrome/common/net/url_fixer_upper.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "chrome/test/base/testing_browser_process.h" 26 #include "chrome/test/base/testing_browser_process.h"
27 #include "chrome/test/base/testing_profile.h" 27 #include "chrome/test/base/testing_profile.h"
28 #include "content/public/test/test_browser_thread_bundle.h" 28 #include "content/public/test/test_browser_thread_bundle.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 30
31 using base::ASCIIToUTF16;
31 using base::Time; 32 using base::Time;
32 using base::TimeDelta; 33 using base::TimeDelta;
33 34
34 using content::TestBrowserThreadBundle; 35 using content::TestBrowserThreadBundle;
35 36
36 struct TestURLInfo { 37 struct TestURLInfo {
37 const char* url; 38 const char* url;
38 const char* title; 39 const char* title;
39 int visit_count; 40 int visit_count;
40 int typed_count; 41 int typed_count;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // be more recent than the "archived history" threshold for the data to go 241 // be more recent than the "archived history" threshold for the data to go
241 // into the main database. 242 // into the main database.
242 // 243 //
243 // TODO(brettw) It would be nice if we could test this behavior, in which 244 // TODO(brettw) It would be nice if we could test this behavior, in which
244 // case the time would be specifed in the test_db structure. 245 // case the time would be specifed in the test_db structure.
245 Time visit_time = Time::Now() - TimeDelta::FromDays(80); 246 Time visit_time = Time::Now() - TimeDelta::FromDays(80);
246 247
247 for (size_t i = 0; i < arraysize(test_db); ++i) { 248 for (size_t i = 0; i < arraysize(test_db); ++i) {
248 const TestURLInfo& cur = test_db[i]; 249 const TestURLInfo& cur = test_db[i];
249 const GURL current_url(cur.url); 250 const GURL current_url(cur.url);
250 history_service_->AddPageWithDetails(current_url, UTF8ToUTF16(cur.title), 251 history_service_->AddPageWithDetails(current_url,
252 base::UTF8ToUTF16(cur.title),
251 cur.visit_count, cur.typed_count, 253 cur.visit_count, cur.typed_count,
252 visit_time, false, 254 visit_time, false,
253 history::SOURCE_BROWSED); 255 history::SOURCE_BROWSED);
254 } 256 }
255 257
256 history_service_->AddPageWithDetails( 258 history_service_->AddPageWithDetails(
257 GURL("http://p/"), UTF8ToUTF16("p"), 0, 0, 259 GURL("http://p/"), base::UTF8ToUTF16("p"), 0, 0,
258 Time::Now() - 260 Time::Now() -
259 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1), 261 TimeDelta::FromDays(history::kLowQualityMatchAgeLimitInDays - 1),
260 false, history::SOURCE_BROWSED); 262 false, history::SOURCE_BROWSED);
261 } 263 }
262 264
263 void HistoryURLProviderTest::RunTest( 265 void HistoryURLProviderTest::RunTest(
264 const base::string16 text, 266 const base::string16 text,
265 const base::string16& desired_tld, 267 const base::string16& desired_tld,
266 bool prevent_inline_autocomplete, 268 bool prevent_inline_autocomplete,
267 const UrlAndLegalDefault* expected_urls, 269 const UrlAndLegalDefault* expected_urls,
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 struct TestCase { 422 struct TestCase {
421 const char* url; 423 const char* url;
422 int count; 424 int count;
423 } test_cases[] = { 425 } test_cases[] = {
424 {"http://redirects/A", 30}, 426 {"http://redirects/A", 30},
425 {"http://redirects/B", 20}, 427 {"http://redirects/B", 20},
426 {"http://redirects/C", 10} 428 {"http://redirects/C", 10}
427 }; 429 };
428 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { 430 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
429 history_service_->AddPageWithDetails(GURL(test_cases[i].url), 431 history_service_->AddPageWithDetails(GURL(test_cases[i].url),
430 UTF8ToUTF16("Title"), test_cases[i].count, test_cases[i].count, 432 ASCIIToUTF16("Title"), test_cases[i].count, test_cases[i].count,
431 Time::Now(), false, history::SOURCE_BROWSED); 433 Time::Now(), false, history::SOURCE_BROWSED);
432 } 434 }
433 435
434 // Create a B->C->A redirect chain, but set the visit counts such that they 436 // Create a B->C->A redirect chain, but set the visit counts such that they
435 // will appear in A,B,C order in the results. The autocomplete query will 437 // will appear in A,B,C order in the results. The autocomplete query will
436 // search for the most recent visit when looking for redirects, so this will 438 // search for the most recent visit when looking for redirects, so this will
437 // be found even though the previous visits had no redirects. 439 // be found even though the previous visits had no redirects.
438 history::RedirectList redirects_to_a; 440 history::RedirectList redirects_to_a;
439 redirects_to_a.push_back(GURL(test_cases[1].url)); 441 redirects_to_a.push_back(GURL(test_cases[1].url));
440 redirects_to_a.push_back(GURL(test_cases[2].url)); 442 redirects_to_a.push_back(GURL(test_cases[2].url));
441 redirects_to_a.push_back(GURL(test_cases[0].url)); 443 redirects_to_a.push_back(GURL(test_cases[0].url));
442 history_service_->AddPage(GURL(test_cases[0].url), base::Time::Now(), 444 history_service_->AddPage(GURL(test_cases[0].url), base::Time::Now(),
443 NULL, 0, GURL(), redirects_to_a, content::PAGE_TRANSITION_TYPED, 445 NULL, 0, GURL(), redirects_to_a, content::PAGE_TRANSITION_TYPED,
444 history::SOURCE_BROWSED, true); 446 history::SOURCE_BROWSED, true);
445 447
446 // Because all the results are part of a redirect chain with other results, 448 // Because all the results are part of a redirect chain with other results,
447 // all but the first one (A) should be culled. We should get the default 449 // all but the first one (A) should be culled. We should get the default
448 // "what you typed" result, plus this one. 450 // "what you typed" result, plus this one.
449 const base::string16 typing(ASCIIToUTF16("http://redirects/")); 451 const base::string16 typing(ASCIIToUTF16("http://redirects/"));
450 const UrlAndLegalDefault expected_results[] = { 452 const UrlAndLegalDefault expected_results[] = {
451 { UTF16ToUTF8(typing), true }, 453 { base::UTF16ToUTF8(typing), true },
452 { test_cases[0].url, false } 454 { test_cases[0].url, false }
453 }; 455 };
454 RunTest(typing, base::string16(), true, expected_results, 456 RunTest(typing, base::string16(), true, expected_results,
455 arraysize(expected_results)); 457 arraysize(expected_results));
456 } 458 }
457 459
458 TEST_F(HistoryURLProviderTest, WhatYouTyped) { 460 TEST_F(HistoryURLProviderTest, WhatYouTyped) {
459 // Make sure we suggest a What You Typed match at the right times. 461 // Make sure we suggest a What You Typed match at the right times.
460 RunTest(ASCIIToUTF16("wytmatch"), base::string16(), false, NULL, 0); 462 RunTest(ASCIIToUTF16("wytmatch"), base::string16(), false, NULL, 0);
461 RunTest(ASCIIToUTF16("wytmatch foo bar"), base::string16(), false, NULL, 0); 463 RunTest(ASCIIToUTF16("wytmatch foo bar"), base::string16(), false, NULL, 0);
(...skipping 21 matching lines...) Expand all
483 } 485 }
484 486
485 TEST_F(HistoryURLProviderTest, Fixup) { 487 TEST_F(HistoryURLProviderTest, Fixup) {
486 // Test for various past crashes we've had. 488 // Test for various past crashes we've had.
487 RunTest(ASCIIToUTF16("\\"), base::string16(), false, NULL, 0); 489 RunTest(ASCIIToUTF16("\\"), base::string16(), false, NULL, 0);
488 RunTest(ASCIIToUTF16("#"), base::string16(), false, NULL, 0); 490 RunTest(ASCIIToUTF16("#"), base::string16(), false, NULL, 0);
489 RunTest(ASCIIToUTF16("%20"), base::string16(), false, NULL, 0); 491 RunTest(ASCIIToUTF16("%20"), base::string16(), false, NULL, 0);
490 const UrlAndLegalDefault fixup_crash[] = { 492 const UrlAndLegalDefault fixup_crash[] = {
491 { "http://%EF%BD%A5@s/", true } 493 { "http://%EF%BD%A5@s/", true }
492 }; 494 };
493 RunTest(WideToUTF16(L"\uff65@s"), base::string16(), false, fixup_crash, 495 RunTest(base::WideToUTF16(L"\uff65@s"), base::string16(), false, fixup_crash,
494 arraysize(fixup_crash)); 496 arraysize(fixup_crash));
495 RunTest(WideToUTF16(L"\u2015\u2015@ \uff7c"), base::string16(), false, 497 RunTest(base::WideToUTF16(L"\u2015\u2015@ \uff7c"), base::string16(), false,
496 NULL, 0); 498 NULL, 0);
497 499
498 // Fixing up "file:" should result in an inline autocomplete offset of just 500 // Fixing up "file:" should result in an inline autocomplete offset of just
499 // after "file:", not just after "file://". 501 // after "file:", not just after "file://".
500 const base::string16 input_1(ASCIIToUTF16("file:")); 502 const base::string16 input_1(ASCIIToUTF16("file:"));
501 const UrlAndLegalDefault fixup_1[] = { 503 const UrlAndLegalDefault fixup_1[] = {
502 { "file:///C:/foo.txt", true } 504 { "file:///C:/foo.txt", true }
503 }; 505 };
504 ASSERT_NO_FATAL_FAILURE(RunTest(input_1, base::string16(), false, fixup_1, 506 ASSERT_NO_FATAL_FAILURE(RunTest(input_1, base::string16(), false, fixup_1,
505 arraysize(fixup_1))); 507 arraysize(fixup_1)));
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 struct TestCase { 801 struct TestCase {
800 const char* url; 802 const char* url;
801 int count; 803 int count;
802 } test_cases[] = { 804 } test_cases[] = {
803 {"https://testsearch.com/", 30}, 805 {"https://testsearch.com/", 30},
804 {"https://testsearch.com/?q=foobar", 20}, 806 {"https://testsearch.com/?q=foobar", 20},
805 {"http://foobar.com/", 10} 807 {"http://foobar.com/", 10}
806 }; 808 };
807 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { 809 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
808 history_service_->AddPageWithDetails(GURL(test_cases[i].url), 810 history_service_->AddPageWithDetails(GURL(test_cases[i].url),
809 UTF8ToUTF16("Title"), test_cases[i].count, test_cases[i].count, 811 base::UTF8ToUTF16("Title"), test_cases[i].count, test_cases[i].count,
810 Time::Now(), false, history::SOURCE_BROWSED); 812 Time::Now(), false, history::SOURCE_BROWSED);
811 } 813 }
812 814
813 // We should not see search URLs when typing a previously used query. 815 // We should not see search URLs when typing a previously used query.
814 const UrlAndLegalDefault expected_when_searching_query[] = { 816 const UrlAndLegalDefault expected_when_searching_query[] = {
815 { test_cases[2].url, false } 817 { test_cases[2].url, false }
816 }; 818 };
817 RunTest(ASCIIToUTF16("foobar"), base::string16(), true, 819 RunTest(ASCIIToUTF16("foobar"), base::string16(), true,
818 expected_when_searching_query, arraysize(expected_when_searching_query)); 820 expected_when_searching_query, arraysize(expected_when_searching_query));
819 821
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 EXPECT_EQ(test_cases[i].offsets[match_index], 902 EXPECT_EQ(test_cases[i].offsets[match_index],
901 match.contents_class[match_index].offset); 903 match.contents_class[match_index].offset);
902 EXPECT_EQ(ACMatchClassification::URL | 904 EXPECT_EQ(ACMatchClassification::URL |
903 (match_index == test_cases[i].match_classification_index ? 905 (match_index == test_cases[i].match_classification_index ?
904 ACMatchClassification::MATCH : 0), 906 ACMatchClassification::MATCH : 0),
905 match.contents_class[match_index].style); 907 match.contents_class[match_index].style);
906 } 908 }
907 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]); 909 EXPECT_EQ(npos, test_cases[i].offsets[match.contents_class.size()]);
908 } 910 }
909 } 911 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_url_provider.cc ('k') | chrome/browser/autocomplete/keyword_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698