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

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

Issue 2910843002: [Cleanup] Move all browsertests to use ScopedFeatureList to modify features
Patch Set: comments addressed and updated Created 3 years, 5 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 <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"
chaopeng 2017/06/30 19:32:37 I got warning point to add this header file.
Ilya Sherman 2017/07/03 21:21:59 That makes sense, since you're adding OS_ #if-stmt
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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() {}
269 272
270 protected: 273 protected:
271 void SetUpCommandLine(base::CommandLine* cmdline) override { 274 void SetUp() override {
272 cmdline->AppendSwitchASCII(switches::kEnableFeatures, "UseGoogleLocalNtp"); 275 scoped_feature_list_.InitAndEnableFeature(features::kUseGoogleLocalNtp);
276 InProcessBrowserTest::SetUp();
273 } 277 }
274 278
275 void SetUserSelectedDefaultSearchProvider(const std::string& base_url) { 279 void SetUserSelectedDefaultSearchProvider(const std::string& base_url) {
276 base::ThreadRestrictions::ScopedAllowIO allow_io; 280 base::ThreadRestrictions::ScopedAllowIO allow_io;
277 TemplateURLData data; 281 TemplateURLData data;
278 data.SetShortName(base::UTF8ToUTF16(base_url)); 282 data.SetShortName(base::UTF8ToUTF16(base_url));
279 data.SetKeyword(base::UTF8ToUTF16(base_url)); 283 data.SetKeyword(base::UTF8ToUTF16(base_url));
280 data.SetURL(base_url + "url?bar={searchTerms}"); 284 data.SetURL(base_url + "url?bar={searchTerms}");
281 285
282 TemplateURLService* template_url_service = 286 TemplateURLService* template_url_service =
283 TemplateURLServiceFactory::GetForProfile(browser()->profile()); 287 TemplateURLServiceFactory::GetForProfile(browser()->profile());
284 TemplateURL* template_url = 288 TemplateURL* template_url =
285 template_url_service->Add(base::MakeUnique<TemplateURL>(data)); 289 template_url_service->Add(base::MakeUnique<TemplateURL>(data));
286 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); 290 template_url_service->SetUserSelectedDefaultSearchProvider(template_url);
287 } 291 }
292
293 private:
294 base::test::ScopedFeatureList scoped_feature_list_;
288 }; 295 };
289 296
290 IN_PROC_BROWSER_TEST_F(LocalNTPSmokeTest, GoogleNTPLoadsWithoutError) { 297 IN_PROC_BROWSER_TEST_F(LocalNTPSmokeTest, GoogleNTPLoadsWithoutError) {
291 // Open a new blank tab. 298 // Open a new blank tab.
292 content::WebContents* active_tab = OpenNewTab(browser(), GURL("about:blank")); 299 content::WebContents* active_tab = OpenNewTab(browser(), GURL("about:blank"));
293 ASSERT_FALSE(search::IsInstantNTP(active_tab)); 300 ASSERT_FALSE(search::IsInstantNTP(active_tab));
294 301
295 // Attach a console observer, listening for any message ("*" pattern). 302 // Attach a console observer, listening for any message ("*" pattern).
296 content::ConsoleObserverDelegate console_observer(active_tab, "*"); 303 content::ConsoleObserverDelegate console_observer(active_tab, "*");
297 active_tab->SetDelegate(&console_observer); 304 active_tab->SetDelegate(&console_observer);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 375
369 private: 376 private:
370 base::Optional<OneGoogleBarData> one_google_bar_data_; 377 base::Optional<OneGoogleBarData> one_google_bar_data_;
371 }; 378 };
372 379
373 class LocalNTPOneGoogleBarSmokeTest : public InProcessBrowserTest { 380 class LocalNTPOneGoogleBarSmokeTest : public InProcessBrowserTest {
374 public: 381 public:
375 LocalNTPOneGoogleBarSmokeTest() {} 382 LocalNTPOneGoogleBarSmokeTest() {}
376 383
377 protected: 384 protected:
378 void SetUpCommandLine(base::CommandLine* cmdline) override { 385 void SetUp() override {
379 cmdline->AppendSwitchASCII(switches::kEnableFeatures, 386 #if !defined(OS_ANDROID) && !defined(OS_IOS)
380 "UseGoogleLocalNtp,OneGoogleBarOnLocalNtp"); 387 scoped_feature_list_.InitWithFeatures(
388 {features::kUseGoogleLocalNtp, features::kOneGoogleBarOnLocalNtp}, {});
389 #else
390 scoped_feature_list_.InitAndEnableFeature(features::kUseGoogleLocalNtp);
391 #endif
392 InProcessBrowserTest::SetUp();
381 } 393 }
382 394
383 void SetUpInProcessBrowserTestFixture() override { 395 void SetUpInProcessBrowserTestFixture() override {
384 will_create_browser_context_services_subscription_ = 396 will_create_browser_context_services_subscription_ =
385 BrowserContextDependencyManager::GetInstance() 397 BrowserContextDependencyManager::GetInstance()
386 ->RegisterWillCreateBrowserContextServicesCallbackForTesting( 398 ->RegisterWillCreateBrowserContextServicesCallbackForTesting(
387 base::Bind(&LocalNTPOneGoogleBarSmokeTest:: 399 base::Bind(&LocalNTPOneGoogleBarSmokeTest::
388 OnWillCreateBrowserContextServices, 400 OnWillCreateBrowserContextServices,
389 base::Unretained(this))); 401 base::Unretained(this)));
390 } 402 }
(...skipping 14 matching lines...) Expand all
405 } 417 }
406 418
407 void OnWillCreateBrowserContextServices(content::BrowserContext* context) { 419 void OnWillCreateBrowserContextServices(content::BrowserContext* context) {
408 OneGoogleBarServiceFactory::GetInstance()->SetTestingFactory( 420 OneGoogleBarServiceFactory::GetInstance()->SetTestingFactory(
409 context, &LocalNTPOneGoogleBarSmokeTest::CreateOneGoogleBarService); 421 context, &LocalNTPOneGoogleBarSmokeTest::CreateOneGoogleBarService);
410 } 422 }
411 423
412 std::unique_ptr< 424 std::unique_ptr<
413 base::CallbackList<void(content::BrowserContext*)>::Subscription> 425 base::CallbackList<void(content::BrowserContext*)>::Subscription>
414 will_create_browser_context_services_subscription_; 426 will_create_browser_context_services_subscription_;
427 base::test::ScopedFeatureList scoped_feature_list_;
415 }; 428 };
416 429
417 IN_PROC_BROWSER_TEST_F(LocalNTPOneGoogleBarSmokeTest, 430 IN_PROC_BROWSER_TEST_F(LocalNTPOneGoogleBarSmokeTest,
418 NTPLoadsWithoutErrorOnNetworkFailure) { 431 NTPLoadsWithoutErrorOnNetworkFailure) {
419 // Open a new blank tab. 432 // Open a new blank tab.
420 content::WebContents* active_tab = OpenNewTab(browser(), GURL("about:blank")); 433 content::WebContents* active_tab = OpenNewTab(browser(), GURL("about:blank"));
421 ASSERT_FALSE(search::IsInstantNTP(active_tab)); 434 ASSERT_FALSE(search::IsInstantNTP(active_tab));
422 435
423 // Attach a console observer, listening for any message ("*" pattern). 436 // Attach a console observer, listening for any message ("*" pattern).
424 content::ConsoleObserverDelegate console_observer(active_tab, "*"); 437 content::ConsoleObserverDelegate console_observer(active_tab, "*");
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 477
465 bool in_head_ran = false; 478 bool in_head_ran = false;
466 ASSERT_TRUE(instant_test_utils::GetBoolFromJS( 479 ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
467 active_tab, "!!window.inHeadRan", &in_head_ran)); 480 active_tab, "!!window.inHeadRan", &in_head_ran));
468 EXPECT_TRUE(in_head_ran); 481 EXPECT_TRUE(in_head_ran);
469 bool after_bar_ran = false; 482 bool after_bar_ran = false;
470 ASSERT_TRUE(instant_test_utils::GetBoolFromJS( 483 ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
471 active_tab, "!!window.afterBarRan", &after_bar_ran)); 484 active_tab, "!!window.afterBarRan", &after_bar_ran));
472 EXPECT_TRUE(after_bar_ran); 485 EXPECT_TRUE(after_bar_ran);
473 } 486 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698