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

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

Issue 397723003: Omnibox: Don't Autocomplete Previously-Issued Search Queries (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adds test Created 6 years, 5 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
« no previous file with comments | « chrome/browser/autocomplete/search_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 AutocompleteMatch term_match_b; 811 AutocompleteMatch term_match_b;
812 EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b)); 812 EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
813 EXPECT_GT(term_match_b.relevance, term_match_a.relevance); 813 EXPECT_GT(term_match_b.relevance, term_match_a.relevance);
814 EXPECT_GT(term_match_a.relevance, wyt_match.relevance); 814 EXPECT_GT(term_match_a.relevance, wyt_match.relevance);
815 EXPECT_TRUE(term_match_b.allowed_to_be_default_match); 815 EXPECT_TRUE(term_match_b.allowed_to_be_default_match);
816 EXPECT_TRUE(term_match_a.allowed_to_be_default_match); 816 EXPECT_TRUE(term_match_a.allowed_to_be_default_match);
817 EXPECT_TRUE(wyt_match.allowed_to_be_default_match); 817 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
818 } 818 }
819 819
820 // An autocompleted multiword search should not be replaced by a different 820 // An autocompleted multiword search should not be replaced by a different
821 // autocompletion while the user is still typing a valid prefix. 821 // autocompletion while the user is still typing a valid prefix unless the
822 // user has typed the prefix as a query before.
822 TEST_F(SearchProviderTest, DontReplacePreviousAutocompletion) { 823 TEST_F(SearchProviderTest, DontReplacePreviousAutocompletion) {
823 GURL term_url_a(AddSearchToHistory(default_t_url_, 824 GURL term_url_a(AddSearchToHistory(default_t_url_,
824 ASCIIToUTF16("four searches aaa"), 2)); 825 ASCIIToUTF16("four searches aaa"), 3));
825 GURL term_url_b(AddSearchToHistory(default_t_url_, 826 GURL term_url_b(AddSearchToHistory(default_t_url_,
826 ASCIIToUTF16("four searches bbb"), 1)); 827 ASCIIToUTF16("four searches bbb"), 1));
828 GURL term_url_c(AddSearchToHistory(default_t_url_,
829 ASCIIToUTF16("four searches"), 1));
827 profile_.BlockUntilHistoryProcessesPendingRequests(); 830 profile_.BlockUntilHistoryProcessesPendingRequests();
828 831
829 AutocompleteMatch wyt_match; 832 AutocompleteMatch wyt_match;
830 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("fo"), 833 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("fo"),
831 &wyt_match)); 834 &wyt_match));
832 ASSERT_EQ(3u, provider_->matches().size()); 835 ASSERT_EQ(4u, provider_->matches().size());
833 AutocompleteMatch term_match_a; 836 AutocompleteMatch term_match_a;
834 EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a)); 837 EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a));
835 AutocompleteMatch term_match_b; 838 AutocompleteMatch term_match_b;
836 EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b)); 839 EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
840 AutocompleteMatch term_match_c;
841 EXPECT_TRUE(FindMatchWithDestination(term_url_c, &term_match_c));
837 EXPECT_GT(term_match_a.relevance, wyt_match.relevance); 842 EXPECT_GT(term_match_a.relevance, wyt_match.relevance);
843 // We don't care about the relative order of b and c.
844 EXPECT_GT(wyt_match.relevance, term_match_b.relevance);
845 EXPECT_GT(wyt_match.relevance, term_match_c.relevance);
846 EXPECT_TRUE(term_match_a.allowed_to_be_default_match);
847 EXPECT_TRUE(term_match_b.allowed_to_be_default_match);
848 EXPECT_TRUE(term_match_c.allowed_to_be_default_match);
849 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
850
851 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("four se"),
852 &wyt_match));
853 ASSERT_EQ(4u, provider_->matches().size());
854 EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a));
855 EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
856 EXPECT_TRUE(FindMatchWithDestination(term_url_c, &term_match_c));
857 EXPECT_GT(term_match_a.relevance, wyt_match.relevance);
858 EXPECT_GT(wyt_match.relevance, term_match_b.relevance);
859 EXPECT_GT(wyt_match.relevance, term_match_c.relevance);
860 EXPECT_TRUE(term_match_a.allowed_to_be_default_match);
861 EXPECT_TRUE(term_match_b.allowed_to_be_default_match);
862 EXPECT_TRUE(term_match_c.allowed_to_be_default_match);
863 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
864
865 // For the exact previously-issued query, the what-you-typed match should win.
866 ASSERT_NO_FATAL_FAILURE(
867 QueryForInputAndSetWYTMatch(ASCIIToUTF16("four searches"), &wyt_match));
868 ASSERT_EQ(3u, provider_->matches().size());
869 EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a));
870 EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
871 EXPECT_GT(wyt_match.relevance, term_match_a.relevance);
838 EXPECT_GT(wyt_match.relevance, term_match_b.relevance); 872 EXPECT_GT(wyt_match.relevance, term_match_b.relevance);
839 EXPECT_TRUE(term_match_a.allowed_to_be_default_match); 873 EXPECT_TRUE(term_match_a.allowed_to_be_default_match);
840 EXPECT_TRUE(term_match_b.allowed_to_be_default_match); 874 EXPECT_TRUE(term_match_b.allowed_to_be_default_match);
841 EXPECT_TRUE(wyt_match.allowed_to_be_default_match); 875 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
842
843 ASSERT_NO_FATAL_FAILURE(QueryForInputAndSetWYTMatch(ASCIIToUTF16("four se"),
844 &wyt_match));
845 ASSERT_EQ(3u, provider_->matches().size());
846 EXPECT_TRUE(FindMatchWithDestination(term_url_a, &term_match_a));
847 EXPECT_TRUE(FindMatchWithDestination(term_url_b, &term_match_b));
848 EXPECT_GT(term_match_a.relevance, wyt_match.relevance);
849 EXPECT_GT(wyt_match.relevance, term_match_b.relevance);
850 EXPECT_TRUE(term_match_a.allowed_to_be_default_match);
851 EXPECT_TRUE(term_match_b.allowed_to_be_default_match);
852 EXPECT_TRUE(wyt_match.allowed_to_be_default_match);
853 } 876 }
854 877
855 // Non-completable multiword searches should not crowd out single-word searches. 878 // Non-completable multiword searches should not crowd out single-word searches.
856 TEST_F(SearchProviderTest, DontCrowdOutSingleWords) { 879 TEST_F(SearchProviderTest, DontCrowdOutSingleWords) {
857 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("five"), 1)); 880 GURL term_url(AddSearchToHistory(default_t_url_, ASCIIToUTF16("five"), 1));
858 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches bbb"), 1); 881 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches bbb"), 1);
859 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches ccc"), 1); 882 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches ccc"), 1);
860 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches ddd"), 1); 883 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches ddd"), 1);
861 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches eee"), 1); 884 AddSearchToHistory(default_t_url_, ASCIIToUTF16("five searches eee"), 1);
862 profile_.BlockUntilHistoryProcessesPendingRequests(); 885 profile_.BlockUntilHistoryProcessesPendingRequests();
(...skipping 2330 matching lines...) Expand 10 before | Expand all | Expand 10 after
3193 3216
3194 // The expiration time is always updated. 3217 // The expiration time is always updated.
3195 provider_->GetSessionToken(); 3218 provider_->GetSessionToken();
3196 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_; 3219 base::TimeTicks expiration_time_1 = provider_->token_expiration_time_;
3197 base::PlatformThread::Sleep(kSmallDelta); 3220 base::PlatformThread::Sleep(kSmallDelta);
3198 provider_->GetSessionToken(); 3221 provider_->GetSessionToken();
3199 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_; 3222 base::TimeTicks expiration_time_2 = provider_->token_expiration_time_;
3200 EXPECT_GT(expiration_time_2, expiration_time_1); 3223 EXPECT_GT(expiration_time_2, expiration_time_1);
3201 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta); 3224 EXPECT_GE(expiration_time_2, expiration_time_1 + kSmallDelta);
3202 } 3225 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/search_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698