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

Side by Side Diff: chrome/browser/ui/search/instant_search_prerenderer_unittest.cc

Issue 1260033003: Partially componentize //chrome/browser/search/search.{h,cc} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation on iOS Created 5 years, 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ui/search/instant_search_prerenderer.h" 5 #include "chrome/browser/ui/search/instant_search_prerenderer.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 EXPECT_NE(static_cast<PrerenderHandle*>(NULL), prerender_handle()); 217 EXPECT_NE(static_cast<PrerenderHandle*>(NULL), prerender_handle());
218 } 218 }
219 }; 219 };
220 220
221 TEST_F(InstantSearchPrerendererTest, GetSearchTermsFromPrerenderedPage) { 221 TEST_F(InstantSearchPrerendererTest, GetSearchTermsFromPrerenderedPage) {
222 Init(false, false); 222 Init(false, false);
223 InstantSearchPrerenderer* prerenderer = GetInstantSearchPrerenderer(); 223 InstantSearchPrerenderer* prerenderer = GetInstantSearchPrerenderer();
224 GURL url(GetPrerenderURL()); 224 GURL url(GetPrerenderURL());
225 EXPECT_EQ(GURL("https://www.google.com/instant?ion=1&foo=foo#foo=foo&strk"), 225 EXPECT_EQ(GURL("https://www.google.com/instant?ion=1&foo=foo#foo=foo&strk"),
226 url); 226 url);
227 EXPECT_EQ(base::UTF16ToASCII(prerenderer->get_last_query()), 227 EXPECT_EQ(
228 base::UTF16ToASCII( 228 base::UTF16ToASCII(prerenderer->get_last_query()),
229 chrome::ExtractSearchTermsFromURL(profile(), url))); 229 base::UTF16ToASCII(search::ExtractSearchTermsFromURL(profile(), url)));
230 230
231 // Assume the prerendered page prefetched search results for the query 231 // Assume the prerendered page prefetched search results for the query
232 // "flowers". 232 // "flowers".
233 SetLastQuery(ASCIIToUTF16("flowers")); 233 SetLastQuery(ASCIIToUTF16("flowers"));
234 EXPECT_EQ("flowers", base::UTF16ToASCII(prerenderer->get_last_query())); 234 EXPECT_EQ("flowers", base::UTF16ToASCII(prerenderer->get_last_query()));
235 EXPECT_EQ(base::UTF16ToASCII(prerenderer->get_last_query()), 235 EXPECT_EQ(
236 base::UTF16ToASCII( 236 base::UTF16ToASCII(prerenderer->get_last_query()),
237 chrome::ExtractSearchTermsFromURL(profile(), url))); 237 base::UTF16ToASCII(search::ExtractSearchTermsFromURL(profile(), url)));
238 } 238 }
239 239
240 TEST_F(InstantSearchPrerendererTest, PrefetchSearchResults) { 240 TEST_F(InstantSearchPrerendererTest, PrefetchSearchResults) {
241 Init(true, true); 241 Init(true, true);
242 EXPECT_TRUE(prerender_handle()->IsFinishedLoading()); 242 EXPECT_TRUE(prerender_handle()->IsFinishedLoading());
243 InstantSearchPrerenderer* prerenderer = GetInstantSearchPrerenderer(); 243 InstantSearchPrerenderer* prerenderer = GetInstantSearchPrerenderer();
244 prerenderer->Prerender( 244 prerenderer->Prerender(
245 InstantSuggestion(ASCIIToUTF16("flowers"), std::string())); 245 InstantSuggestion(ASCIIToUTF16("flowers"), std::string()));
246 EXPECT_EQ("flowers", base::UTF16ToASCII(prerenderer->get_last_query())); 246 EXPECT_EQ("flowers", base::UTF16ToASCII(prerenderer->get_last_query()));
247 EXPECT_TRUE(MessageWasSent( 247 EXPECT_TRUE(MessageWasSent(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 340
341 AutocompleteMatch url_type_match(NULL, 1100, true, 341 AutocompleteMatch url_type_match(NULL, 1100, true,
342 AutocompleteMatchType::URL_WHAT_YOU_TYPED); 342 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
343 EXPECT_FALSE(AutocompleteMatch::IsSearchType(url_type_match.type)); 343 EXPECT_FALSE(AutocompleteMatch::IsSearchType(url_type_match.type));
344 EXPECT_FALSE(prerenderer->IsAllowed(url_type_match, active_tab)); 344 EXPECT_FALSE(prerenderer->IsAllowed(url_type_match, active_tab));
345 345
346 // Search results page supports Instant search. InstantSearchPrerenderer is 346 // Search results page supports Instant search. InstantSearchPrerenderer is
347 // used only when the underlying page doesn't support Instant. 347 // used only when the underlying page doesn't support Instant.
348 NavigateAndCommitActiveTab(GURL("https://www.google.com/alt#quux=foo&strk")); 348 NavigateAndCommitActiveTab(GURL("https://www.google.com/alt#quux=foo&strk"));
349 active_tab = GetActiveWebContents(); 349 active_tab = GetActiveWebContents();
350 EXPECT_FALSE(chrome::ExtractSearchTermsFromURL(profile(), 350 EXPECT_FALSE(
351 active_tab->GetURL()).empty()); 351 search::ExtractSearchTermsFromURL(profile(), active_tab->GetURL())
352 EXPECT_FALSE(chrome::ShouldPrefetchSearchResultsOnSRP()); 352 .empty());
353 EXPECT_FALSE(search::ShouldPrefetchSearchResultsOnSRP());
353 EXPECT_FALSE(prerenderer->IsAllowed(search_type_match, active_tab)); 354 EXPECT_FALSE(prerenderer->IsAllowed(search_type_match, active_tab));
354 } 355 }
355 356
356 TEST_F(InstantSearchPrerendererTest, UsePrerenderPage) { 357 TEST_F(InstantSearchPrerendererTest, UsePrerenderPage) {
357 PrerenderSearchQuery(ASCIIToUTF16("foo")); 358 PrerenderSearchQuery(ASCIIToUTF16("foo"));
358 359
359 // Open a search results page. A prerendered page exists for |url|. Make sure 360 // Open a search results page. A prerendered page exists for |url|. Make sure
360 // the browser swaps the current tab contents with the prerendered contents. 361 // the browser swaps the current tab contents with the prerendered contents.
361 GURL url("https://www.google.com/alt#quux=foo&strk"); 362 GURL url("https://www.google.com/alt#quux=foo&strk");
362 browser()->OpenURL(content::OpenURLParams(url, Referrer(), CURRENT_TAB, 363 browser()->OpenURL(content::OpenURLParams(url, Referrer(), CURRENT_TAB,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 base::Tuple<base::string16, EmbeddedSearchRequestParams> params; 533 base::Tuple<base::string16, EmbeddedSearchRequestParams> params;
533 ChromeViewMsg_SearchBoxSubmit::Read(message, &params); 534 ChromeViewMsg_SearchBoxSubmit::Read(message, &params);
534 EXPECT_EQ("foo", base::UTF16ToASCII(base::get<0>(params))); 535 EXPECT_EQ("foo", base::UTF16ToASCII(base::get<0>(params)));
535 EXPECT_EQ("f", base::UTF16ToASCII(base::get<1>(params).original_query)); 536 EXPECT_EQ("f", base::UTF16ToASCII(base::get<1>(params).original_query));
536 EXPECT_EQ("utf-8", base::UTF16ToASCII(base::get<1>(params).input_encoding)); 537 EXPECT_EQ("utf-8", base::UTF16ToASCII(base::get<1>(params).input_encoding));
537 EXPECT_EQ("", base::UTF16ToASCII(base::get<1>(params).rlz_parameter_value)); 538 EXPECT_EQ("", base::UTF16ToASCII(base::get<1>(params).rlz_parameter_value));
538 EXPECT_EQ("chrome...0", 539 EXPECT_EQ("chrome...0",
539 base::UTF16ToASCII(base::get<1>(params).assisted_query_stats)); 540 base::UTF16ToASCII(base::get<1>(params).assisted_query_stats));
540 } 541 }
541 #endif 542 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_search_prerenderer.cc ('k') | chrome/browser/ui/search/local_ntp_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698