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