OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 2341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2352 "?www.abc.com", "c.com", true, false }, | 2352 "?www.abc.com", "c.com", true, false }, |
2353 { "?abc.com", "http://www.abc.com", | 2353 { "?abc.com", "http://www.abc.com", |
2354 "?www.abc.com", "", true, true }, | 2354 "?www.abc.com", "", true, true }, |
2355 }; | 2355 }; |
2356 | 2356 |
2357 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 2357 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { |
2358 // First test regular mode. | 2358 // First test regular mode. |
2359 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); | 2359 QueryForInput(ASCIIToUTF16(cases[i].input), false, false); |
2360 AutocompleteMatch match( | 2360 AutocompleteMatch match( |
2361 provider_->NavigationToMatch(SearchProvider::NavigationResult( | 2361 provider_->NavigationToMatch(SearchProvider::NavigationResult( |
2362 *provider_.get(), &profile_, GURL(cases[i].url), | 2362 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), |
2363 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), | 2363 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), |
2364 false, 0, false, ASCIIToUTF16(cases[i].input), std::string()))); | 2364 false, 0, false, ASCIIToUTF16(cases[i].input), std::string()))); |
2365 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), | 2365 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
2366 match.inline_autocompletion); | 2366 match.inline_autocompletion); |
2367 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); | 2367 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), match.fill_into_edit); |
2368 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_regular_mode, | 2368 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_regular_mode, |
2369 match.allowed_to_be_default_match); | 2369 match.allowed_to_be_default_match); |
2370 | 2370 |
2371 // Then test prevent-inline-autocomplete mode. | 2371 // Then test prevent-inline-autocomplete mode. |
2372 QueryForInput(ASCIIToUTF16(cases[i].input), true, false); | 2372 QueryForInput(ASCIIToUTF16(cases[i].input), true, false); |
2373 AutocompleteMatch match_prevent_inline( | 2373 AutocompleteMatch match_prevent_inline( |
2374 provider_->NavigationToMatch(SearchProvider::NavigationResult( | 2374 provider_->NavigationToMatch(SearchProvider::NavigationResult( |
2375 *provider_.get(), &profile_, GURL(cases[i].url), | 2375 ChromeAutocompleteSchemeClassifier(&profile_), GURL(cases[i].url), |
2376 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), | 2376 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), |
2377 false, 0, false, ASCIIToUTF16(cases[i].input), std::string()))); | 2377 false, 0, false, ASCIIToUTF16(cases[i].input), std::string()))); |
2378 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), | 2378 EXPECT_EQ(ASCIIToUTF16(cases[i].inline_autocompletion), |
2379 match_prevent_inline.inline_autocompletion); | 2379 match_prevent_inline.inline_autocompletion); |
2380 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), | 2380 EXPECT_EQ(ASCIIToUTF16(cases[i].fill_into_edit), |
2381 match_prevent_inline.fill_into_edit); | 2381 match_prevent_inline.fill_into_edit); |
2382 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_prevent_inline_mode, | 2382 EXPECT_EQ(cases[i].allowed_to_be_default_match_in_prevent_inline_mode, |
2383 match_prevent_inline.allowed_to_be_default_match); | 2383 match_prevent_inline.allowed_to_be_default_match); |
2384 } | 2384 } |
2385 } | 2385 } |
2386 | 2386 |
2387 // Verifies that "http://" is not trimmed for input that is a leading substring. | 2387 // Verifies that "http://" is not trimmed for input that is a leading substring. |
2388 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { | 2388 TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { |
2389 const base::string16 input(ASCIIToUTF16("ht")); | 2389 const base::string16 input(ASCIIToUTF16("ht")); |
2390 const base::string16 url(ASCIIToUTF16("http://a.com")); | 2390 const base::string16 url(ASCIIToUTF16("http://a.com")); |
2391 const SearchProvider::NavigationResult result( | 2391 const SearchProvider::NavigationResult result( |
2392 *provider_.get(), &profile_, GURL(url), AutocompleteMatchType::NAVSUGGEST, | 2392 ChromeAutocompleteSchemeClassifier(&profile_), GURL(url), |
| 2393 AutocompleteMatchType::NAVSUGGEST, |
2393 base::string16(), std::string(), false, 0, false, input, std::string()); | 2394 base::string16(), std::string(), false, 0, false, input, std::string()); |
2394 | 2395 |
2395 // Check the offset and strings when inline autocompletion is allowed. | 2396 // Check the offset and strings when inline autocompletion is allowed. |
2396 QueryForInput(input, false, false); | 2397 QueryForInput(input, false, false); |
2397 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); | 2398 AutocompleteMatch match_inline(provider_->NavigationToMatch(result)); |
2398 EXPECT_EQ(url, match_inline.fill_into_edit); | 2399 EXPECT_EQ(url, match_inline.fill_into_edit); |
2399 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); | 2400 EXPECT_EQ(url.substr(2), match_inline.inline_autocompletion); |
2400 EXPECT_TRUE(match_inline.allowed_to_be_default_match); | 2401 EXPECT_TRUE(match_inline.allowed_to_be_default_match); |
2401 EXPECT_EQ(url, match_inline.contents); | 2402 EXPECT_EQ(url, match_inline.contents); |
2402 | 2403 |
2403 // Check the same strings when inline autocompletion is prevented. | 2404 // Check the same strings when inline autocompletion is prevented. |
2404 QueryForInput(input, true, false); | 2405 QueryForInput(input, true, false); |
2405 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); | 2406 AutocompleteMatch match_prevent(provider_->NavigationToMatch(result)); |
2406 EXPECT_EQ(url, match_prevent.fill_into_edit); | 2407 EXPECT_EQ(url, match_prevent.fill_into_edit); |
2407 EXPECT_FALSE(match_prevent.allowed_to_be_default_match); | 2408 EXPECT_FALSE(match_prevent.allowed_to_be_default_match); |
2408 EXPECT_EQ(url, match_prevent.contents); | 2409 EXPECT_EQ(url, match_prevent.contents); |
2409 } | 2410 } |
2410 | 2411 |
2411 // Verifies that input "w" marks a more significant domain label than "www.". | 2412 // Verifies that input "w" marks a more significant domain label than "www.". |
2412 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { | 2413 TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { |
2413 QueryForInput(ASCIIToUTF16("w"), false, false); | 2414 QueryForInput(ASCIIToUTF16("w"), false, false); |
2414 AutocompleteMatch match( | 2415 AutocompleteMatch match( |
2415 provider_->NavigationToMatch(SearchProvider::NavigationResult( | 2416 provider_->NavigationToMatch(SearchProvider::NavigationResult( |
2416 *provider_.get(), &profile_, GURL("http://www.wow.com"), | 2417 ChromeAutocompleteSchemeClassifier(&profile_), |
| 2418 GURL("http://www.wow.com"), |
2417 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), | 2419 AutocompleteMatchType::NAVSUGGEST, base::string16(), std::string(), |
2418 false, 0, false, ASCIIToUTF16("w"), std::string()))); | 2420 false, 0, false, ASCIIToUTF16("w"), std::string()))); |
2419 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); | 2421 EXPECT_EQ(ASCIIToUTF16("ow.com"), match.inline_autocompletion); |
2420 EXPECT_TRUE(match.allowed_to_be_default_match); | 2422 EXPECT_TRUE(match.allowed_to_be_default_match); |
2421 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); | 2423 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.fill_into_edit); |
2422 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); | 2424 EXPECT_EQ(ASCIIToUTF16("www.wow.com"), match.contents); |
2423 | 2425 |
2424 // Ensure that the match for input "w" is marked on "wow" and not "www". | 2426 // Ensure that the match for input "w" is marked on "wow" and not "www". |
2425 ASSERT_EQ(3U, match.contents_class.size()); | 2427 ASSERT_EQ(3U, match.contents_class.size()); |
2426 EXPECT_EQ(0U, match.contents_class[0].offset); | 2428 EXPECT_EQ(0U, match.contents_class[0].offset); |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3196 | 3198 |
3197 // The expiration time is always updated. | 3199 // The expiration time is always updated. |
3198 provider_->GetSessionToken(); | 3200 provider_->GetSessionToken(); |
3199 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_; | 3201 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_; |
3200 base::PlatformThread::Sleep(kSmallDelta); | 3202 base::PlatformThread::Sleep(kSmallDelta); |
3201 provider_->GetSessionToken(); | 3203 provider_->GetSessionToken(); |
3202 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_; | 3204 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_; |
3203 EXPECT_GT(expiration_time_2, expiration_time_1); | 3205 EXPECT_GT(expiration_time_2, expiration_time_1); |
3204 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta); | 3206 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta); |
3205 } | 3207 } |
OLD | NEW |