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/content_settings/host_content_settings_map.h" | 11 #include "chrome/browser/content_settings/host_content_settings_map.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/extension_service_test_base.h" | 13 #include "chrome/browser/extensions/extension_service_test_base.h" |
14 #include "chrome/browser/extensions/tab_helper.h" | 14 #include "chrome/browser/extensions/tab_helper.h" |
15 #include "chrome/browser/notifications/desktop_notification_service.h" | |
16 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | |
17 #include "chrome/browser/prefs/session_startup_pref.h" | 15 #include "chrome/browser/prefs/session_startup_pref.h" |
18 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" | 16 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" |
19 #include "chrome/browser/profile_resetter/profile_resetter_test_base.h" | 17 #include "chrome/browser/profile_resetter/profile_resetter_test_base.h" |
20 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" | 18 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" |
21 #include "chrome/browser/search_engines/template_url_service_factory.h" | 19 #include "chrome/browser/search_engines/template_url_service_factory.h" |
22 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 20 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
23 #include "chrome/browser/themes/theme_service.h" | 21 #include "chrome/browser/themes/theme_service.h" |
24 #include "chrome/browser/themes/theme_service_factory.h" | 22 #include "chrome/browser/themes/theme_service_factory.h" |
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
26 #include "chrome/browser/webdata/web_data_service_factory.h" | 24 #include "chrome/browser/webdata/web_data_service_factory.h" |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 ResetAndWait(ProfileResetter::HOMEPAGE); | 485 ResetAndWait(ProfileResetter::HOMEPAGE); |
488 | 486 |
489 EXPECT_TRUE(prefs->GetBoolean(prefs::kHomePageIsNewTabPage)); | 487 EXPECT_TRUE(prefs->GetBoolean(prefs::kHomePageIsNewTabPage)); |
490 EXPECT_EQ("http://www.foo.com", prefs->GetString(prefs::kHomePage)); | 488 EXPECT_EQ("http://www.foo.com", prefs->GetString(prefs::kHomePage)); |
491 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowHomeButton)); | 489 EXPECT_FALSE(prefs->GetBoolean(prefs::kShowHomeButton)); |
492 } | 490 } |
493 | 491 |
494 TEST_F(ProfileResetterTest, ResetContentSettings) { | 492 TEST_F(ProfileResetterTest, ResetContentSettings) { |
495 HostContentSettingsMap* host_content_settings_map = | 493 HostContentSettingsMap* host_content_settings_map = |
496 profile()->GetHostContentSettingsMap(); | 494 profile()->GetHostContentSettingsMap(); |
497 DesktopNotificationService* notification_service = | |
498 DesktopNotificationServiceFactory::GetForProfile(profile()); | |
499 ContentSettingsPattern pattern = | 495 ContentSettingsPattern pattern = |
500 ContentSettingsPattern::FromString("[*.]example.org"); | 496 ContentSettingsPattern::FromString("[*.]example.org"); |
501 std::map<ContentSettingsType, ContentSetting> default_settings; | 497 std::map<ContentSettingsType, ContentSetting> default_settings; |
502 | 498 |
503 for (int type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 499 for (int type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
504 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 500 if (type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE || |
505 notification_service->SetDefaultContentSetting(CONTENT_SETTING_BLOCK); | 501 type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT || |
506 notification_service->GrantPermission(GURL("http://foo.de")); | 502 type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { |
507 } else if (type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE || | |
508 type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT || | |
509 type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { | |
510 // These types are excluded because one can't call | 503 // These types are excluded because one can't call |
511 // GetDefaultContentSetting() for them. | 504 // GetDefaultContentSetting() for them. |
512 } else { | 505 } else { |
513 ContentSettingsType content_type = static_cast<ContentSettingsType>(type); | 506 ContentSettingsType content_type = static_cast<ContentSettingsType>(type); |
514 ContentSetting default_setting = | 507 ContentSetting default_setting = |
515 host_content_settings_map->GetDefaultContentSetting(content_type, | 508 host_content_settings_map->GetDefaultContentSetting(content_type, |
516 NULL); | 509 NULL); |
517 default_settings[content_type] = default_setting; | 510 default_settings[content_type] = default_setting; |
518 ContentSetting wildcard_setting = | 511 ContentSetting wildcard_setting = |
519 default_setting == CONTENT_SETTING_BLOCK ? CONTENT_SETTING_ALLOW | 512 default_setting == CONTENT_SETTING_BLOCK ? CONTENT_SETTING_ALLOW |
(...skipping 24 matching lines...) Expand all Loading... |
544 host_content_settings_map->GetSettingsForOneType( | 537 host_content_settings_map->GetSettingsForOneType( |
545 content_type, std::string(), &host_settings); | 538 content_type, std::string(), &host_settings); |
546 EXPECT_EQ(2U, host_settings.size()); | 539 EXPECT_EQ(2U, host_settings.size()); |
547 } | 540 } |
548 } | 541 } |
549 } | 542 } |
550 | 543 |
551 ResetAndWait(ProfileResetter::CONTENT_SETTINGS); | 544 ResetAndWait(ProfileResetter::CONTENT_SETTINGS); |
552 | 545 |
553 for (int type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { | 546 for (int type = 0; type < CONTENT_SETTINGS_NUM_TYPES; ++type) { |
554 if (type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { | 547 ContentSettingsType content_type = static_cast<ContentSettingsType>(type); |
555 EXPECT_EQ(CONTENT_SETTING_ASK, | 548 if (HostContentSettingsMap::ContentTypeHasCompoundValue(content_type) || |
556 notification_service->GetDefaultContentSetting(NULL)); | 549 type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE || |
557 EXPECT_EQ(CONTENT_SETTING_ASK, | 550 content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT || |
558 notification_service->GetContentSetting(GURL("http://foo.de"))); | 551 content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) |
559 } else { | 552 continue; |
560 ContentSettingsType content_type = static_cast<ContentSettingsType>(type); | 553 ContentSetting default_setting = |
561 if (HostContentSettingsMap::ContentTypeHasCompoundValue(content_type) || | 554 host_content_settings_map->GetDefaultContentSetting(content_type, |
562 type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE || | |
563 content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT || | |
564 content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) | |
565 continue; | |
566 ContentSetting default_setting = | |
567 host_content_settings_map->GetDefaultContentSetting(content_type, | |
568 NULL); | 555 NULL); |
569 EXPECT_TRUE(default_settings.count(content_type)); | 556 EXPECT_TRUE(default_settings.count(content_type)); |
570 EXPECT_EQ(default_settings[content_type], default_setting); | 557 EXPECT_EQ(default_settings[content_type], default_setting); |
571 if (!HostContentSettingsMap::ContentTypeHasCompoundValue(content_type)) { | 558 if (!HostContentSettingsMap::ContentTypeHasCompoundValue(content_type)) { |
572 ContentSetting site_setting = | 559 ContentSetting site_setting = |
573 host_content_settings_map->GetContentSetting( | 560 host_content_settings_map->GetContentSetting( |
574 GURL("example.org"), | 561 GURL("example.org"), |
575 GURL(), | 562 GURL(), |
576 content_type, | 563 content_type, |
577 std::string()); | 564 std::string()); |
578 EXPECT_EQ(default_setting, site_setting); | 565 EXPECT_EQ(default_setting, site_setting); |
579 } | 566 } |
580 | 567 |
581 ContentSettingsForOneType host_settings; | 568 ContentSettingsForOneType host_settings; |
582 host_content_settings_map->GetSettingsForOneType( | 569 host_content_settings_map->GetSettingsForOneType( |
583 content_type, std::string(), &host_settings); | 570 content_type, std::string(), &host_settings); |
584 EXPECT_EQ(1U, host_settings.size()); | 571 EXPECT_EQ(1U, host_settings.size()); |
585 } | |
586 } | 572 } |
587 } | 573 } |
588 | 574 |
589 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) { | 575 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) { |
590 service_->Init(); | 576 service_->Init(); |
591 | 577 |
592 base::ScopedTempDir temp_dir; | 578 base::ScopedTempDir temp_dir; |
593 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 579 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
594 | 580 |
595 scoped_refptr<Extension> theme = | 581 scoped_refptr<Extension> theme = |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 new ResettableSettingsSnapshot(profile())); | 1091 new ResettableSettingsSnapshot(profile())); |
1106 deleted_snapshot->RequestShortcuts(base::Bind(&FeedbackCapture::Fail, | 1092 deleted_snapshot->RequestShortcuts(base::Bind(&FeedbackCapture::Fail, |
1107 base::Unretained(&capture))); | 1093 base::Unretained(&capture))); |
1108 deleted_snapshot.reset(); | 1094 deleted_snapshot.reset(); |
1109 // Running remaining tasks shouldn't trigger the callback to be called as | 1095 // Running remaining tasks shouldn't trigger the callback to be called as |
1110 // |deleted_snapshot| was deleted before it could run. | 1096 // |deleted_snapshot| was deleted before it could run. |
1111 base::MessageLoop::current()->RunUntilIdle(); | 1097 base::MessageLoop::current()->RunUntilIdle(); |
1112 } | 1098 } |
1113 | 1099 |
1114 } // namespace | 1100 } // namespace |
OLD | NEW |