| 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/optional.h" | 12 #include "base/optional.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/test/scoped_feature_list.h" |
| 14 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/search/one_google_bar/one_google_bar_data.h" | 18 #include "chrome/browser/search/one_google_bar/one_google_bar_data.h" |
| 18 #include "chrome/browser/search/one_google_bar/one_google_bar_fetcher.h" | 19 #include "chrome/browser/search/one_google_bar/one_google_bar_fetcher.h" |
| 19 #include "chrome/browser/search/one_google_bar/one_google_bar_service.h" | 20 #include "chrome/browser/search/one_google_bar/one_google_bar_service.h" |
| 20 #include "chrome/browser/search/one_google_bar/one_google_bar_service_factory.h" | 21 #include "chrome/browser/search/one_google_bar/one_google_bar_service_factory.h" |
| 21 #include "chrome/browser/search/search.h" | 22 #include "chrome/browser/search/search.h" |
| 22 #include "chrome/browser/search_engines/template_url_service_factory.h" | 23 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 23 #include "chrome/browser/signin/signin_manager_factory.h" | 24 #include "chrome/browser/signin/signin_manager_factory.h" |
| 24 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/browser_commands.h" | 26 #include "chrome/browser/ui/browser_commands.h" |
| 26 #include "chrome/browser/ui/search/instant_test_base.h" | 27 #include "chrome/browser/ui/search/instant_test_base.h" |
| 27 #include "chrome/browser/ui/search/instant_test_utils.h" | 28 #include "chrome/browser/ui/search/instant_test_utils.h" |
| 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 30 #include "chrome/common/chrome_features.h" |
| 29 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 31 #include "chrome/test/base/in_process_browser_test.h" | 33 #include "chrome/test/base/in_process_browser_test.h" |
| 32 #include "chrome/test/base/ui_test_utils.h" | 34 #include "chrome/test/base/ui_test_utils.h" |
| 33 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 35 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 34 #include "components/prefs/pref_service.h" | 36 #include "components/prefs/pref_service.h" |
| 35 #include "components/search_engines/template_url.h" | 37 #include "components/search_engines/template_url.h" |
| 36 #include "components/search_engines/template_url_data.h" | 38 #include "components/search_engines/template_url_data.h" |
| 37 #include "components/search_engines/template_url_service.h" | 39 #include "components/search_engines/template_url_service.h" |
| 38 #include "components/signin/core/browser/signin_manager.h" | 40 #include "components/signin/core/browser/signin_manager.h" |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 264 } |
| 263 | 265 |
| 264 // In contrast to LocalNTPTest, this one doesn't set up any special NTP | 266 // In contrast to LocalNTPTest, this one doesn't set up any special NTP |
| 265 // wrangling. It just turns on the local NTP. | 267 // wrangling. It just turns on the local NTP. |
| 266 class LocalNTPSmokeTest : public InProcessBrowserTest { | 268 class LocalNTPSmokeTest : public InProcessBrowserTest { |
| 267 public: | 269 public: |
| 268 LocalNTPSmokeTest() {} | 270 LocalNTPSmokeTest() {} |
| 269 | 271 |
| 270 protected: | 272 protected: |
| 271 void SetUpCommandLine(base::CommandLine* cmdline) override { | 273 void SetUpCommandLine(base::CommandLine* cmdline) override { |
| 272 cmdline->AppendSwitchASCII(switches::kEnableFeatures, "UseGoogleLocalNtp"); | 274 scoped_feature_list_.InitAndEnableFeature(features::kUseGoogleLocalNtp); |
| 273 } | 275 } |
| 274 | 276 |
| 275 void SetUserSelectedDefaultSearchProvider(const std::string& base_url) { | 277 void SetUserSelectedDefaultSearchProvider(const std::string& base_url) { |
| 276 base::ThreadRestrictions::ScopedAllowIO allow_io; | 278 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 277 TemplateURLData data; | 279 TemplateURLData data; |
| 278 data.SetShortName(base::UTF8ToUTF16(base_url)); | 280 data.SetShortName(base::UTF8ToUTF16(base_url)); |
| 279 data.SetKeyword(base::UTF8ToUTF16(base_url)); | 281 data.SetKeyword(base::UTF8ToUTF16(base_url)); |
| 280 data.SetURL(base_url + "url?bar={searchTerms}"); | 282 data.SetURL(base_url + "url?bar={searchTerms}"); |
| 281 | 283 |
| 282 TemplateURLService* template_url_service = | 284 TemplateURLService* template_url_service = |
| 283 TemplateURLServiceFactory::GetForProfile(browser()->profile()); | 285 TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
| 284 TemplateURL* template_url = | 286 TemplateURL* template_url = |
| 285 template_url_service->Add(base::MakeUnique<TemplateURL>(data)); | 287 template_url_service->Add(base::MakeUnique<TemplateURL>(data)); |
| 286 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); | 288 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
| 287 } | 289 } |
| 290 |
| 291 private: |
| 292 base::test::ScopedFeatureList scoped_feature_list_; |
| 288 }; | 293 }; |
| 289 | 294 |
| 290 IN_PROC_BROWSER_TEST_F(LocalNTPSmokeTest, GoogleNTPLoadsWithoutError) { | 295 IN_PROC_BROWSER_TEST_F(LocalNTPSmokeTest, GoogleNTPLoadsWithoutError) { |
| 291 // Open a new blank tab. | 296 // Open a new blank tab. |
| 292 content::WebContents* active_tab = OpenNewTab(browser(), GURL("about:blank")); | 297 content::WebContents* active_tab = OpenNewTab(browser(), GURL("about:blank")); |
| 293 ASSERT_FALSE(search::IsInstantNTP(active_tab)); | 298 ASSERT_FALSE(search::IsInstantNTP(active_tab)); |
| 294 | 299 |
| 295 // Attach a console observer, listening for any message ("*" pattern). | 300 // Attach a console observer, listening for any message ("*" pattern). |
| 296 content::ConsoleObserverDelegate console_observer(active_tab, "*"); | 301 content::ConsoleObserverDelegate console_observer(active_tab, "*"); |
| 297 active_tab->SetDelegate(&console_observer); | 302 active_tab->SetDelegate(&console_observer); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 private: | 374 private: |
| 370 base::Optional<OneGoogleBarData> one_google_bar_data_; | 375 base::Optional<OneGoogleBarData> one_google_bar_data_; |
| 371 }; | 376 }; |
| 372 | 377 |
| 373 class LocalNTPOneGoogleBarSmokeTest : public InProcessBrowserTest { | 378 class LocalNTPOneGoogleBarSmokeTest : public InProcessBrowserTest { |
| 374 public: | 379 public: |
| 375 LocalNTPOneGoogleBarSmokeTest() {} | 380 LocalNTPOneGoogleBarSmokeTest() {} |
| 376 | 381 |
| 377 protected: | 382 protected: |
| 378 void SetUpCommandLine(base::CommandLine* cmdline) override { | 383 void SetUpCommandLine(base::CommandLine* cmdline) override { |
| 379 cmdline->AppendSwitchASCII(switches::kEnableFeatures, | 384 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 380 "UseGoogleLocalNtp,OneGoogleBarOnLocalNtp"); | 385 scoped_feature_list_.InitWithFeatures( |
| 386 {features::kUseGoogleLocalNtp, features::kOneGoogleBarOnLocalNtp}, {}); |
| 387 #else |
| 388 scoped_feature_list_.InitAndEnableFeature(features::kUseGoogleLocalNtp); |
| 389 #endif |
| 381 } | 390 } |
| 382 | 391 |
| 383 void SetUpInProcessBrowserTestFixture() override { | 392 void SetUpInProcessBrowserTestFixture() override { |
| 384 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 393 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 385 | 394 |
| 386 will_create_browser_context_services_subscription_ = | 395 will_create_browser_context_services_subscription_ = |
| 387 BrowserContextDependencyManager::GetInstance() | 396 BrowserContextDependencyManager::GetInstance() |
| 388 ->RegisterWillCreateBrowserContextServicesCallbackForTesting( | 397 ->RegisterWillCreateBrowserContextServicesCallbackForTesting( |
| 389 base::Bind(&LocalNTPOneGoogleBarSmokeTest:: | 398 base::Bind(&LocalNTPOneGoogleBarSmokeTest:: |
| 390 OnWillCreateBrowserContextServices, | 399 OnWillCreateBrowserContextServices, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 407 } | 416 } |
| 408 | 417 |
| 409 void OnWillCreateBrowserContextServices(content::BrowserContext* context) { | 418 void OnWillCreateBrowserContextServices(content::BrowserContext* context) { |
| 410 OneGoogleBarServiceFactory::GetInstance()->SetTestingFactory( | 419 OneGoogleBarServiceFactory::GetInstance()->SetTestingFactory( |
| 411 context, &LocalNTPOneGoogleBarSmokeTest::CreateOneGoogleBarService); | 420 context, &LocalNTPOneGoogleBarSmokeTest::CreateOneGoogleBarService); |
| 412 } | 421 } |
| 413 | 422 |
| 414 std::unique_ptr< | 423 std::unique_ptr< |
| 415 base::CallbackList<void(content::BrowserContext*)>::Subscription> | 424 base::CallbackList<void(content::BrowserContext*)>::Subscription> |
| 416 will_create_browser_context_services_subscription_; | 425 will_create_browser_context_services_subscription_; |
| 426 base::test::ScopedFeatureList scoped_feature_list_; |
| 417 }; | 427 }; |
| 418 | 428 |
| 419 IN_PROC_BROWSER_TEST_F(LocalNTPOneGoogleBarSmokeTest, | 429 IN_PROC_BROWSER_TEST_F(LocalNTPOneGoogleBarSmokeTest, |
| 420 NTPLoadsWithoutErrorOnNetworkFailure) { | 430 NTPLoadsWithoutErrorOnNetworkFailure) { |
| 421 // Open a new blank tab. | 431 // Open a new blank tab. |
| 422 content::WebContents* active_tab = OpenNewTab(browser(), GURL("about:blank")); | 432 content::WebContents* active_tab = OpenNewTab(browser(), GURL("about:blank")); |
| 423 ASSERT_FALSE(search::IsInstantNTP(active_tab)); | 433 ASSERT_FALSE(search::IsInstantNTP(active_tab)); |
| 424 | 434 |
| 425 // Attach a console observer, listening for any message ("*" pattern). | 435 // Attach a console observer, listening for any message ("*" pattern). |
| 426 content::ConsoleObserverDelegate console_observer(active_tab, "*"); | 436 content::ConsoleObserverDelegate console_observer(active_tab, "*"); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 | 476 |
| 467 bool in_head_ran = false; | 477 bool in_head_ran = false; |
| 468 ASSERT_TRUE(instant_test_utils::GetBoolFromJS( | 478 ASSERT_TRUE(instant_test_utils::GetBoolFromJS( |
| 469 active_tab, "!!window.inHeadRan", &in_head_ran)); | 479 active_tab, "!!window.inHeadRan", &in_head_ran)); |
| 470 EXPECT_TRUE(in_head_ran); | 480 EXPECT_TRUE(in_head_ran); |
| 471 bool after_bar_ran = false; | 481 bool after_bar_ran = false; |
| 472 ASSERT_TRUE(instant_test_utils::GetBoolFromJS( | 482 ASSERT_TRUE(instant_test_utils::GetBoolFromJS( |
| 473 active_tab, "!!window.afterBarRan", &after_bar_ran)); | 483 active_tab, "!!window.afterBarRan", &after_bar_ran)); |
| 474 EXPECT_TRUE(after_bar_ran); | 484 EXPECT_TRUE(after_bar_ran); |
| 475 } | 485 } |
| OLD | NEW |