| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/profile_resetter/profile_resetter.h" | 5 #include "chrome/browser/profile_resetter/profile_resetter.h" |
| 6 | 6 |
| 7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/test/scoped_path_override.h" | 10 #include "base/test/scoped_path_override.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_service_test_base.h" | 12 #include "chrome/browser/extensions/extension_service_test_base.h" |
| 13 #include "chrome/browser/extensions/tab_helper.h" | 13 #include "chrome/browser/extensions/tab_helper.h" |
| 14 #include "chrome/browser/prefs/session_startup_pref.h" | 14 #include "chrome/browser/prefs/session_startup_pref.h" |
| 15 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" | 15 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" |
| 16 #include "chrome/browser/profile_resetter/profile_resetter_test_base.h" | 16 #include "chrome/browser/profile_resetter/profile_resetter_test_base.h" |
| 17 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" | 17 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" |
| 18 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 19 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 19 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
| 20 #include "chrome/browser/themes/theme_service.h" | 20 #include "chrome/browser/themes/theme_service.h" |
| 21 #include "chrome/browser/themes/theme_service_factory.h" | 21 #include "chrome/browser/themes/theme_service_factory.h" |
| 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 23 #include "chrome/browser/webdata/web_data_service_factory.h" | 23 #include "chrome/browser/webdata/web_data_service_factory.h" |
| 24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/test/base/browser_with_test_window_test.h" | 25 #include "chrome/test/base/browser_with_test_window_test.h" |
| 26 #include "components/content_settings/core/browser/host_content_settings_map.h" | 26 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 27 #include "components/google/core/browser/google_pref_names.h" | |
| 28 #include "components/search_engines/template_url_service.h" | 27 #include "components/search_engines/template_url_service.h" |
| 29 #include "components/search_engines/template_url_service_client.h" | 28 #include "components/search_engines/template_url_service_client.h" |
| 30 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/test/test_browser_thread.h" | 30 #include "content/public/test/test_browser_thread.h" |
| 32 #include "extensions/browser/extension_registry.h" | 31 #include "extensions/browser/extension_registry.h" |
| 33 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
| 34 #include "extensions/common/manifest_constants.h" | 33 #include "extensions/common/manifest_constants.h" |
| 35 #include "net/http/http_response_headers.h" | 34 #include "net/http/http_response_headers.h" |
| 36 #include "net/http/http_status_code.h" | 35 #include "net/http/http_status_code.h" |
| 37 #include "net/url_request/test_url_fetcher_factory.h" | 36 #include "net/url_request/test_url_fetcher_factory.h" |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 416 |
| 418 | 417 |
| 419 /********************* Tests *********************/ | 418 /********************* Tests *********************/ |
| 420 | 419 |
| 421 TEST_F(ProfileResetterTest, ResetNothing) { | 420 TEST_F(ProfileResetterTest, ResetNothing) { |
| 422 // The callback should be called even if there is nothing to reset. | 421 // The callback should be called even if there is nothing to reset. |
| 423 ResetAndWait(0); | 422 ResetAndWait(0); |
| 424 } | 423 } |
| 425 | 424 |
| 426 TEST_F(ProfileResetterTest, ResetDefaultSearchEngineNonOrganic) { | 425 TEST_F(ProfileResetterTest, ResetDefaultSearchEngineNonOrganic) { |
| 427 PrefService* prefs = profile()->GetPrefs(); | |
| 428 DCHECK(prefs); | |
| 429 prefs->SetString(prefs::kLastPromptedGoogleURL, "http://www.foo.com/"); | |
| 430 | |
| 431 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE, kDistributionConfig); | 426 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE, kDistributionConfig); |
| 432 | 427 |
| 433 TemplateURLService* model = | 428 TemplateURLService* model = |
| 434 TemplateURLServiceFactory::GetForProfile(profile()); | 429 TemplateURLServiceFactory::GetForProfile(profile()); |
| 435 TemplateURL* default_engine = model->GetDefaultSearchProvider(); | 430 TemplateURL* default_engine = model->GetDefaultSearchProvider(); |
| 436 ASSERT_NE(static_cast<TemplateURL*>(NULL), default_engine); | 431 ASSERT_NE(static_cast<TemplateURL*>(NULL), default_engine); |
| 437 EXPECT_EQ(base::ASCIIToUTF16("first"), default_engine->short_name()); | 432 EXPECT_EQ(base::ASCIIToUTF16("first"), default_engine->short_name()); |
| 438 EXPECT_EQ(base::ASCIIToUTF16("firstkey"), default_engine->keyword()); | 433 EXPECT_EQ(base::ASCIIToUTF16("firstkey"), default_engine->keyword()); |
| 439 EXPECT_EQ("http://www.foo.com/s?q={searchTerms}", default_engine->url()); | 434 EXPECT_EQ("http://www.foo.com/s?q={searchTerms}", default_engine->url()); |
| 440 | |
| 441 EXPECT_EQ("", prefs->GetString(prefs::kLastPromptedGoogleURL)); | |
| 442 } | 435 } |
| 443 | 436 |
| 444 TEST_F(ProfileResetterTest, ResetDefaultSearchEnginePartially) { | 437 TEST_F(ProfileResetterTest, ResetDefaultSearchEnginePartially) { |
| 445 // Search engine's logic is tested by | 438 // Search engine's logic is tested by |
| 446 // TemplateURLServiceTest.RepairPrepopulatedSearchEngines. | 439 // TemplateURLServiceTest.RepairPrepopulatedSearchEngines. |
| 447 PrefService* prefs = profile()->GetPrefs(); | |
| 448 DCHECK(prefs); | |
| 449 prefs->SetString(prefs::kLastPromptedGoogleURL, "http://www.foo.com/"); | |
| 450 | |
| 451 // Make sure TemplateURLService has loaded. | 440 // Make sure TemplateURLService has loaded. |
| 452 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE); | 441 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE); |
| 453 | 442 |
| 454 TemplateURLService* model = | 443 TemplateURLService* model = |
| 455 TemplateURLServiceFactory::GetForProfile(profile()); | 444 TemplateURLServiceFactory::GetForProfile(profile()); |
| 456 TemplateURLService::TemplateURLVector urls = model->GetTemplateURLs(); | 445 TemplateURLService::TemplateURLVector urls = model->GetTemplateURLs(); |
| 457 | 446 |
| 458 // The second call should produce no effect. | 447 // The second call should produce no effect. |
| 459 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE); | 448 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE); |
| 460 | 449 |
| 461 EXPECT_EQ(urls, model->GetTemplateURLs()); | 450 EXPECT_EQ(urls, model->GetTemplateURLs()); |
| 462 EXPECT_EQ(std::string(), prefs->GetString(prefs::kLastPromptedGoogleURL)); | |
| 463 } | 451 } |
| 464 | 452 |
| 465 TEST_F(ProfileResetterTest, ResetHomepageNonOrganic) { | 453 TEST_F(ProfileResetterTest, ResetHomepageNonOrganic) { |
| 466 PrefService* prefs = profile()->GetPrefs(); | 454 PrefService* prefs = profile()->GetPrefs(); |
| 467 DCHECK(prefs); | 455 DCHECK(prefs); |
| 468 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, true); | 456 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, true); |
| 469 prefs->SetString(prefs::kHomePage, "http://google.com"); | 457 prefs->SetString(prefs::kHomePage, "http://google.com"); |
| 470 prefs->SetBoolean(prefs::kShowHomeButton, false); | 458 prefs->SetBoolean(prefs::kShowHomeButton, false); |
| 471 | 459 |
| 472 ResetAndWait(ProfileResetter::HOMEPAGE, kDistributionConfig); | 460 ResetAndWait(ProfileResetter::HOMEPAGE, kDistributionConfig); |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 new ResettableSettingsSnapshot(profile())); | 1085 new ResettableSettingsSnapshot(profile())); |
| 1098 deleted_snapshot->RequestShortcuts(base::Bind(&FeedbackCapture::Fail, | 1086 deleted_snapshot->RequestShortcuts(base::Bind(&FeedbackCapture::Fail, |
| 1099 base::Unretained(&capture))); | 1087 base::Unretained(&capture))); |
| 1100 deleted_snapshot.reset(); | 1088 deleted_snapshot.reset(); |
| 1101 // Running remaining tasks shouldn't trigger the callback to be called as | 1089 // Running remaining tasks shouldn't trigger the callback to be called as |
| 1102 // |deleted_snapshot| was deleted before it could run. | 1090 // |deleted_snapshot| was deleted before it could run. |
| 1103 base::MessageLoop::current()->RunUntilIdle(); | 1091 base::MessageLoop::current()->RunUntilIdle(); |
| 1104 } | 1092 } |
| 1105 | 1093 |
| 1106 } // namespace | 1094 } // namespace |
| OLD | NEW |