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

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

Issue 141893009: Create a new helper function to extract search terms from the URL irrespective of the availablility (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 10 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/ui/search/instant_search_prerenderer.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 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 231 }
232 }; 232 };
233 233
234 TEST_F(InstantSearchPrerendererTest, GetSearchTermsFromPrerenderedPage) { 234 TEST_F(InstantSearchPrerendererTest, GetSearchTermsFromPrerenderedPage) {
235 Init(false, false); 235 Init(false, false);
236 InstantSearchPrerenderer* prerenderer = GetInstantSearchPrerenderer(); 236 InstantSearchPrerenderer* prerenderer = GetInstantSearchPrerenderer();
237 GURL url(GetPrerenderURL()); 237 GURL url(GetPrerenderURL());
238 EXPECT_EQ(GURL("https://www.google.com/instant?ion=1&foo=foo#foo=foo&strk"), 238 EXPECT_EQ(GURL("https://www.google.com/instant?ion=1&foo=foo#foo=foo&strk"),
239 url); 239 url);
240 EXPECT_EQ(UTF16ToASCII(prerenderer->get_last_query()), 240 EXPECT_EQ(UTF16ToASCII(prerenderer->get_last_query()),
241 UTF16ToASCII(chrome::GetSearchTermsFromURL(profile(), url))); 241 UTF16ToASCII(chrome::ExtractSearchTermsFromURL(profile(), url)));
242 242
243 // Assume the prerendered page prefetched search results for the query 243 // Assume the prerendered page prefetched search results for the query
244 // "flowers". 244 // "flowers".
245 SetLastQuery(ASCIIToUTF16("flowers")); 245 SetLastQuery(ASCIIToUTF16("flowers"));
246 EXPECT_EQ("flowers", UTF16ToASCII(prerenderer->get_last_query())); 246 EXPECT_EQ("flowers", UTF16ToASCII(prerenderer->get_last_query()));
247 EXPECT_EQ(UTF16ToASCII(prerenderer->get_last_query()), 247 EXPECT_EQ(UTF16ToASCII(prerenderer->get_last_query()),
248 UTF16ToASCII(chrome::GetSearchTermsFromURL(profile(), url))); 248 UTF16ToASCII(chrome::ExtractSearchTermsFromURL(profile(), url)));
249 } 249 }
250 250
251 TEST_F(InstantSearchPrerendererTest, PrefetchSearchResults) { 251 TEST_F(InstantSearchPrerendererTest, PrefetchSearchResults) {
252 Init(true, true); 252 Init(true, true);
253 EXPECT_TRUE(prerender_handle()->IsFinishedLoading()); 253 EXPECT_TRUE(prerender_handle()->IsFinishedLoading());
254 InstantSearchPrerenderer* prerenderer = GetInstantSearchPrerenderer(); 254 InstantSearchPrerenderer* prerenderer = GetInstantSearchPrerenderer();
255 prerenderer->Prerender( 255 prerenderer->Prerender(
256 InstantSuggestion(ASCIIToUTF16("flowers"), std::string())); 256 InstantSuggestion(ASCIIToUTF16("flowers"), std::string()));
257 EXPECT_EQ("flowers", UTF16ToASCII(prerenderer->get_last_query())); 257 EXPECT_EQ("flowers", UTF16ToASCII(prerenderer->get_last_query()));
258 EXPECT_TRUE(MessageWasSent( 258 EXPECT_TRUE(MessageWasSent(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 329
330 AutocompleteMatch url_type_match(NULL, 1100, true, 330 AutocompleteMatch url_type_match(NULL, 1100, true,
331 AutocompleteMatchType::URL_WHAT_YOU_TYPED); 331 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
332 EXPECT_FALSE(AutocompleteMatch::IsSearchType(url_type_match.type)); 332 EXPECT_FALSE(AutocompleteMatch::IsSearchType(url_type_match.type));
333 EXPECT_FALSE(prerenderer->IsAllowed(url_type_match, active_tab)); 333 EXPECT_FALSE(prerenderer->IsAllowed(url_type_match, active_tab));
334 334
335 // Search results page supports Instant search. InstantSearchPrerenderer is 335 // Search results page supports Instant search. InstantSearchPrerenderer is
336 // used only when the underlying page doesn't support Instant. 336 // used only when the underlying page doesn't support Instant.
337 NavigateAndCommitActiveTab(GURL("https://www.google.com/alt#quux=foo&strk")); 337 NavigateAndCommitActiveTab(GURL("https://www.google.com/alt#quux=foo&strk"));
338 active_tab = GetActiveWebContents(); 338 active_tab = GetActiveWebContents();
339 EXPECT_FALSE(chrome::GetSearchTermsFromURL(profile(), active_tab->GetURL()) 339 EXPECT_FALSE(chrome::ExtractSearchTermsFromURL(profile(),
340 .empty()); 340 active_tab->GetURL()).empty());
341 EXPECT_FALSE(chrome::ShouldPrefetchSearchResultsOnSRP()); 341 EXPECT_FALSE(chrome::ShouldPrefetchSearchResultsOnSRP());
342 EXPECT_FALSE(prerenderer->IsAllowed(search_type_match, active_tab)); 342 EXPECT_FALSE(prerenderer->IsAllowed(search_type_match, active_tab));
343 } 343 }
344 344
345 TEST_F(InstantSearchPrerendererTest, UsePrerenderPage) { 345 TEST_F(InstantSearchPrerendererTest, UsePrerenderPage) {
346 PrerenderSearchQuery(ASCIIToUTF16("foo")); 346 PrerenderSearchQuery(ASCIIToUTF16("foo"));
347 347
348 // Open a search results page. A prerendered page exists for |url|. Make sure 348 // Open a search results page. A prerendered page exists for |url|. Make sure
349 // the browser swaps the current tab contents with the prerendered contents. 349 // the browser swaps the current tab contents with the prerendered contents.
350 GURL url("https://www.google.com/alt#quux=foo&strk"); 350 GURL url("https://www.google.com/alt#quux=foo&strk");
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 InstantSearchPrerenderer* prerenderer = GetInstantSearchPrerenderer(); 441 InstantSearchPrerenderer* prerenderer = GetInstantSearchPrerenderer();
442 base::string16 query = ASCIIToUTF16("flowers"); 442 base::string16 query = ASCIIToUTF16("flowers");
443 prerenderer->Prerender(InstantSuggestion(query, std::string())); 443 prerenderer->Prerender(InstantSuggestion(query, std::string()));
444 444
445 // When the Instant search base page hasn't finished loading, 445 // When the Instant search base page hasn't finished loading,
446 // InstantSearchPrerenderer cannot commit any search query to the base page. 446 // InstantSearchPrerenderer cannot commit any search query to the base page.
447 EXPECT_FALSE(prerenderer->CanCommitQuery(GetActiveWebContents(), query)); 447 EXPECT_FALSE(prerenderer->CanCommitQuery(GetActiveWebContents(), query));
448 EXPECT_FALSE(prerenderer->CanCommitQuery(GetActiveWebContents(), 448 EXPECT_FALSE(prerenderer->CanCommitQuery(GetActiveWebContents(),
449 ASCIIToUTF16("joy"))); 449 ASCIIToUTF16("joy")));
450 } 450 }
451
452 #if !defined(OS_IOS) && !defined(OS_ANDROID)
453 class TestUsePrerenderPage : public InstantSearchPrerendererTest {
454 protected:
455 virtual void SetUp() OVERRIDE {
456 // Disable query extraction flag in field trials.
457 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
458 "EmbeddedSearch",
459 "Group1 strk:20 query_extraction:0 prefetch_results:1"));
460 InstantUnitTestBase::SetUpWithoutQueryExtraction();
461 }
462 };
463
464 TEST_F(TestUsePrerenderPage, ExtractSearchTermsAndUsePrerenderPage) {
465 PrerenderSearchQuery(ASCIIToUTF16("foo"));
466
467 // Open a search results page. Query extraction flag is disabled in field
468 // trials. Search results page URL does not contain search terms replacement
469 // key. Make sure UsePrerenderedPage() extracts the search terms from the URL
470 // and uses the prerendered page contents.
471 GURL url("https://www.google.com/alt#quux=foo");
472 browser()->OpenURL(content::OpenURLParams(url, Referrer(), CURRENT_TAB,
473 content::PAGE_TRANSITION_TYPED,
474 false));
475 EXPECT_EQ(GetPrerenderURL(), GetActiveWebContents()->GetURL());
476 EXPECT_EQ(static_cast<PrerenderHandle*>(NULL), prerender_handle());
477 }
478 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_search_prerenderer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698