OLD | NEW |
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/search_tab_helper.h" | 5 #include "chrome/browser/ui/search/search_tab_helper.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 } // namespace | 72 } // namespace |
73 | 73 |
74 class SearchTabHelperTest : public ChromeRenderViewHostTestHarness { | 74 class SearchTabHelperTest : public ChromeRenderViewHostTestHarness { |
75 public: | 75 public: |
76 virtual void SetUp() { | 76 virtual void SetUp() { |
77 ChromeRenderViewHostTestHarness::SetUp(); | 77 ChromeRenderViewHostTestHarness::SetUp(); |
78 SearchTabHelper::CreateForWebContents(web_contents()); | 78 SearchTabHelper::CreateForWebContents(web_contents()); |
79 } | 79 } |
80 | 80 |
81 virtual content::BrowserContext* CreateBrowserContext() OVERRIDE { | 81 virtual content::BrowserContext* CreateBrowserContext() override { |
82 TestingProfile::Builder builder; | 82 TestingProfile::Builder builder; |
83 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), | 83 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), |
84 FakeSigninManagerBase::Build); | 84 FakeSigninManagerBase::Build); |
85 builder.AddTestingFactory( | 85 builder.AddTestingFactory( |
86 ProfileSyncServiceFactory::GetInstance(), | 86 ProfileSyncServiceFactory::GetInstance(), |
87 ProfileSyncServiceMock::BuildMockProfileSyncService); | 87 ProfileSyncServiceMock::BuildMockProfileSyncService); |
88 return builder.Build().release(); | 88 return builder.Build().release(); |
89 } | 89 } |
90 | 90 |
91 // Creates a sign-in manager for tests. If |username| is not empty, the | 91 // Creates a sign-in manager for tests. If |username| is not empty, the |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 : WebContentsObserver(contents) {} | 282 : WebContentsObserver(contents) {} |
283 | 283 |
284 base::string16 title_on_start() { return title_on_start_; } | 284 base::string16 title_on_start() { return title_on_start_; } |
285 base::string16 title_on_commit() { return title_on_commit_; } | 285 base::string16 title_on_commit() { return title_on_commit_; } |
286 | 286 |
287 private: | 287 private: |
288 virtual void DidStartProvisionalLoadForFrame( | 288 virtual void DidStartProvisionalLoadForFrame( |
289 content::RenderFrameHost* /* render_frame_host */, | 289 content::RenderFrameHost* /* render_frame_host */, |
290 const GURL& /* validated_url */, | 290 const GURL& /* validated_url */, |
291 bool /* is_error_page */, | 291 bool /* is_error_page */, |
292 bool /* is_iframe_srcdoc */) OVERRIDE { | 292 bool /* is_iframe_srcdoc */) override { |
293 title_on_start_ = web_contents()->GetTitle(); | 293 title_on_start_ = web_contents()->GetTitle(); |
294 } | 294 } |
295 | 295 |
296 virtual void DidNavigateMainFrame( | 296 virtual void DidNavigateMainFrame( |
297 const content::LoadCommittedDetails& /* details */, | 297 const content::LoadCommittedDetails& /* details */, |
298 const content::FrameNavigateParams& /* params */) OVERRIDE { | 298 const content::FrameNavigateParams& /* params */) override { |
299 title_on_commit_ = web_contents()->GetTitle(); | 299 title_on_commit_ = web_contents()->GetTitle(); |
300 } | 300 } |
301 | 301 |
302 base::string16 title_on_start_; | 302 base::string16 title_on_start_; |
303 base::string16 title_on_commit_; | 303 base::string16 title_on_commit_; |
304 }; | 304 }; |
305 | 305 |
306 TEST_F(SearchTabHelperTest, TitleIsSetForNTP) { | 306 TEST_F(SearchTabHelperTest, TitleIsSetForNTP) { |
307 TabTitleObserver title_observer(web_contents()); | 307 TabTitleObserver title_observer(web_contents()); |
308 NavigateAndCommit(GURL(chrome::kChromeUINewTabURL)); | 308 NavigateAndCommit(GURL(chrome::kChromeUINewTabURL)); |
309 const base::string16 title = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); | 309 const base::string16 title = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
310 EXPECT_EQ(title, title_observer.title_on_start()); | 310 EXPECT_EQ(title, title_observer.title_on_start()); |
311 EXPECT_EQ(title, title_observer.title_on_commit()); | 311 EXPECT_EQ(title, title_observer.title_on_commit()); |
312 EXPECT_EQ(title, web_contents()->GetTitle()); | 312 EXPECT_EQ(title, web_contents()->GetTitle()); |
313 } | 313 } |
314 | 314 |
315 class SearchTabHelperWindowTest : public BrowserWithTestWindowTest { | 315 class SearchTabHelperWindowTest : public BrowserWithTestWindowTest { |
316 protected: | 316 protected: |
317 virtual void SetUp() OVERRIDE { | 317 virtual void SetUp() override { |
318 BrowserWithTestWindowTest::SetUp(); | 318 BrowserWithTestWindowTest::SetUp(); |
319 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 319 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
320 profile(), &TemplateURLServiceFactory::BuildInstanceFor); | 320 profile(), &TemplateURLServiceFactory::BuildInstanceFor); |
321 TemplateURLService* template_url_service = | 321 TemplateURLService* template_url_service = |
322 TemplateURLServiceFactory::GetForProfile(profile()); | 322 TemplateURLServiceFactory::GetForProfile(profile()); |
323 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); | 323 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); |
324 | 324 |
325 TemplateURLData data; | 325 TemplateURLData data; |
326 data.SetURL("http://foo.com/url?bar={searchTerms}"); | 326 data.SetURL("http://foo.com/url?bar={searchTerms}"); |
327 data.instant_url = "http://foo.com/instant?" | 327 data.instant_url = "http://foo.com/instant?" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 CommitPendingLoad(controller); | 397 CommitPendingLoad(controller); |
398 EXPECT_NE(GURL(chrome::kChromeSearchLocalNtpUrl), | 398 EXPECT_NE(GURL(chrome::kChromeSearchLocalNtpUrl), |
399 controller->GetLastCommittedEntry()->GetURL()); | 399 controller->GetLastCommittedEntry()->GetURL()); |
400 } | 400 } |
401 | 401 |
402 class SearchTabHelperPrerenderTest : public InstantUnitTestBase { | 402 class SearchTabHelperPrerenderTest : public InstantUnitTestBase { |
403 public: | 403 public: |
404 virtual ~SearchTabHelperPrerenderTest() {} | 404 virtual ~SearchTabHelperPrerenderTest() {} |
405 | 405 |
406 protected: | 406 protected: |
407 virtual void SetUp() OVERRIDE { | 407 virtual void SetUp() override { |
408 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 408 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
409 "EmbeddedSearch", | 409 "EmbeddedSearch", |
410 "Group1 espv:89 prefetch_results:1 " | 410 "Group1 espv:89 prefetch_results:1 " |
411 "prerender_instant_url_on_omnibox_focus:1")); | 411 "prerender_instant_url_on_omnibox_focus:1")); |
412 InstantUnitTestBase::SetUp(); | 412 InstantUnitTestBase::SetUp(); |
413 | 413 |
414 AddTab(browser(), GURL(chrome::kChromeUINewTabURL)); | 414 AddTab(browser(), GURL(chrome::kChromeUINewTabURL)); |
415 prerender::PrerenderManagerFactory::GetForProfile(browser()->profile())-> | 415 prerender::PrerenderManagerFactory::GetForProfile(browser()->profile())-> |
416 OnCookieStoreLoaded(); | 416 OnCookieStoreLoaded(); |
417 SearchTabHelper::FromWebContents(web_contents())->set_omnibox_has_focus_fn( | 417 SearchTabHelper::FromWebContents(web_contents())->set_omnibox_has_focus_fn( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 } | 458 } |
459 | 459 |
460 TEST_F(SearchTabHelperPrerenderTest, | 460 TEST_F(SearchTabHelperPrerenderTest, |
461 OnTabActivatedNoPrerenderIfOmniboxBlurred) { | 461 OnTabActivatedNoPrerenderIfOmniboxBlurred) { |
462 SearchTabHelperPrerenderTest::omnibox_has_focus_ = false; | 462 SearchTabHelperPrerenderTest::omnibox_has_focus_ = false; |
463 SearchTabHelper* search_tab_helper = | 463 SearchTabHelper* search_tab_helper = |
464 SearchTabHelper::FromWebContents(web_contents()); | 464 SearchTabHelper::FromWebContents(web_contents()); |
465 search_tab_helper->OnTabActivated(); | 465 search_tab_helper->OnTabActivated(); |
466 ASSERT_FALSE(IsInstantURLMarkedForPrerendering()); | 466 ASSERT_FALSE(IsInstantURLMarkedForPrerendering()); |
467 } | 467 } |
OLD | NEW |