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

Side by Side Diff: chrome/browser/profile_resetter/profile_resetter_unittest.cc

Issue 1318083005: Remove HostContentSettingsMap::ContentTypeHasCompoundValue function (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove-num-types-enum-3
Patch Set: Created 5 years, 3 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 (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/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/test/scoped_path_override.h" 11 #include "base/test/scoped_path_override.h"
12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_service_test_base.h" 14 #include "chrome/browser/extensions/extension_service_test_base.h"
15 #include "chrome/browser/extensions/tab_helper.h" 15 #include "chrome/browser/extensions/tab_helper.h"
16 #include "chrome/browser/prefs/session_startup_pref.h" 16 #include "chrome/browser/prefs/session_startup_pref.h"
17 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" 17 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h"
18 #include "chrome/browser/profile_resetter/profile_resetter_test_base.h" 18 #include "chrome/browser/profile_resetter/profile_resetter_test_base.h"
19 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" 19 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h"
20 #include "chrome/browser/search_engines/template_url_service_factory.h" 20 #include "chrome/browser/search_engines/template_url_service_factory.h"
21 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 21 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
22 #include "chrome/browser/themes/theme_service.h" 22 #include "chrome/browser/themes/theme_service.h"
23 #include "chrome/browser/themes/theme_service_factory.h" 23 #include "chrome/browser/themes/theme_service_factory.h"
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" 24 #include "chrome/browser/ui/tabs/tab_strip_model.h"
25 #include "chrome/browser/web_data_service_factory.h" 25 #include "chrome/browser/web_data_service_factory.h"
26 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
27 #include "chrome/test/base/browser_with_test_window_test.h" 27 #include "chrome/test/base/browser_with_test_window_test.h"
28 #include "components/content_settings/core/browser/content_settings_info.h"
29 #include "components/content_settings/core/browser/content_settings_registry.h"
28 #include "components/content_settings/core/browser/host_content_settings_map.h" 30 #include "components/content_settings/core/browser/host_content_settings_map.h"
29 #include "components/content_settings/core/browser/website_settings_info.h" 31 #include "components/content_settings/core/browser/website_settings_info.h"
30 #include "components/content_settings/core/browser/website_settings_registry.h"
31 #include "components/search_engines/template_url_service.h" 32 #include "components/search_engines/template_url_service.h"
32 #include "components/search_engines/template_url_service_client.h" 33 #include "components/search_engines/template_url_service_client.h"
33 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
34 #include "content/public/test/test_browser_thread.h" 35 #include "content/public/test/test_browser_thread.h"
35 #include "extensions/browser/extension_registry.h" 36 #include "extensions/browser/extension_registry.h"
36 #include "extensions/common/extension.h" 37 #include "extensions/common/extension.h"
37 #include "extensions/common/manifest_constants.h" 38 #include "extensions/common/manifest_constants.h"
38 #include "net/http/http_response_headers.h" 39 #include "net/http/http_response_headers.h"
39 #include "net/http/http_status_code.h" 40 #include "net/http/http_status_code.h"
40 #include "net/url_request/test_url_fetcher_factory.h" 41 #include "net/url_request/test_url_fetcher_factory.h"
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 485
485 TEST_F(ProfileResetterTest, ResetContentSettings) { 486 TEST_F(ProfileResetterTest, ResetContentSettings) {
486 HostContentSettingsMap* host_content_settings_map = 487 HostContentSettingsMap* host_content_settings_map =
487 HostContentSettingsMapFactory::GetForProfile(profile()); 488 HostContentSettingsMapFactory::GetForProfile(profile());
488 ContentSettingsPattern pattern = 489 ContentSettingsPattern pattern =
489 ContentSettingsPattern::FromString("[*.]example.org"); 490 ContentSettingsPattern::FromString("[*.]example.org");
490 std::map<ContentSettingsType, ContentSetting> default_settings; 491 std::map<ContentSettingsType, ContentSetting> default_settings;
491 492
492 // TODO(raymes): Clean up this test so that we don't have such ugly iteration 493 // TODO(raymes): Clean up this test so that we don't have such ugly iteration
493 // over the content settings. 494 // over the content settings.
494 content_settings::WebsiteSettingsRegistry* registry = 495 content_settings::ContentSettingsRegistry* registry =
495 content_settings::WebsiteSettingsRegistry::GetInstance(); 496 content_settings::ContentSettingsRegistry::GetInstance();
496 for (const content_settings::WebsiteSettingsInfo* info : *registry) { 497 for (const content_settings::ContentSettingsInfo* info : *registry) {
497 ContentSettingsType content_type = info->type(); 498 ContentSettingsType content_type = info->website_settings_info()->type();
498 if (content_type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE || 499 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT ||
499 content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT ||
500 content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { 500 content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) {
501 // These types are excluded because one can't call 501 // These types are excluded because one can't call
502 // GetDefaultContentSetting() for them. 502 // GetDefaultContentSetting() for them.
503 continue; 503 continue;
504 } 504 }
505 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) { 505 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
506 // This has been deprecated so we can neither set nor get it's value. 506 // This has been deprecated so we can neither set nor get it's value.
507 continue; 507 continue;
508 } 508 }
509 ContentSetting default_setting = 509 ContentSetting default_setting =
510 host_content_settings_map->GetDefaultContentSetting(content_type, NULL); 510 host_content_settings_map->GetDefaultContentSetting(content_type, NULL);
511 default_settings[content_type] = default_setting; 511 default_settings[content_type] = default_setting;
512 ContentSetting wildcard_setting = default_setting == CONTENT_SETTING_BLOCK 512 ContentSetting wildcard_setting = default_setting == CONTENT_SETTING_BLOCK
513 ? CONTENT_SETTING_ALLOW 513 ? CONTENT_SETTING_ALLOW
514 : CONTENT_SETTING_BLOCK; 514 : CONTENT_SETTING_BLOCK;
515 ContentSetting site_setting = default_setting == CONTENT_SETTING_ALLOW 515 ContentSetting site_setting = default_setting == CONTENT_SETTING_ALLOW
516 ? CONTENT_SETTING_ALLOW 516 ? CONTENT_SETTING_ALLOW
517 : CONTENT_SETTING_BLOCK; 517 : CONTENT_SETTING_BLOCK;
518 if (HostContentSettingsMap::IsSettingAllowedForType( 518 if (HostContentSettingsMap::IsSettingAllowedForType(
519 profile()->GetPrefs(), wildcard_setting, content_type)) { 519 profile()->GetPrefs(), wildcard_setting, content_type)) {
520 host_content_settings_map->SetDefaultContentSetting(content_type, 520 host_content_settings_map->SetDefaultContentSetting(content_type,
521 wildcard_setting); 521 wildcard_setting);
522 } 522 }
523 if (!HostContentSettingsMap::ContentTypeHasCompoundValue(content_type) && 523 if (HostContentSettingsMap::IsSettingAllowedForType(
524 HostContentSettingsMap::IsSettingAllowedForType(
525 profile()->GetPrefs(), site_setting, content_type)) { 524 profile()->GetPrefs(), site_setting, content_type)) {
526 host_content_settings_map->SetContentSetting( 525 host_content_settings_map->SetContentSetting(
527 pattern, ContentSettingsPattern::Wildcard(), content_type, 526 pattern, ContentSettingsPattern::Wildcard(), content_type,
528 std::string(), site_setting); 527 std::string(), site_setting);
529 ContentSettingsForOneType host_settings; 528 ContentSettingsForOneType host_settings;
530 host_content_settings_map->GetSettingsForOneType( 529 host_content_settings_map->GetSettingsForOneType(
531 content_type, std::string(), &host_settings); 530 content_type, std::string(), &host_settings);
532 EXPECT_EQ(2U, host_settings.size()); 531 EXPECT_EQ(2U, host_settings.size());
533 } 532 }
534 } 533 }
535 534
536 ResetAndWait(ProfileResetter::CONTENT_SETTINGS); 535 ResetAndWait(ProfileResetter::CONTENT_SETTINGS);
537 536
538 for (const content_settings::WebsiteSettingsInfo* info : *registry) { 537 for (const content_settings::ContentSettingsInfo* info : *registry) {
539 ContentSettingsType content_type = info->type(); 538 ContentSettingsType content_type = info->website_settings_info()->type();
540 if (HostContentSettingsMap::ContentTypeHasCompoundValue(content_type) || 539 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT ||
541 content_type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE ||
542 content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT ||
543 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM || 540 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM ||
544 content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) 541 content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS)
545 continue; 542 continue;
546 ContentSetting default_setting = 543 ContentSetting default_setting =
547 host_content_settings_map->GetDefaultContentSetting(content_type, 544 host_content_settings_map->GetDefaultContentSetting(content_type,
548 NULL); 545 NULL);
549 EXPECT_TRUE(default_settings.count(content_type)); 546 EXPECT_TRUE(default_settings.count(content_type));
550 EXPECT_EQ(default_settings[content_type], default_setting); 547 EXPECT_EQ(default_settings[content_type], default_setting);
551 if (!HostContentSettingsMap::ContentTypeHasCompoundValue(content_type)) { 548 ContentSetting site_setting = host_content_settings_map->GetContentSetting(
552 ContentSetting site_setting = 549 GURL("example.org"), GURL(), content_type, std::string());
553 host_content_settings_map->GetContentSetting( 550 EXPECT_EQ(default_setting, site_setting);
554 GURL("example.org"),
555 GURL(),
556 content_type,
557 std::string());
558 EXPECT_EQ(default_setting, site_setting);
559 }
560 551
561 ContentSettingsForOneType host_settings; 552 ContentSettingsForOneType host_settings;
562 host_content_settings_map->GetSettingsForOneType( 553 host_content_settings_map->GetSettingsForOneType(
563 content_type, std::string(), &host_settings); 554 content_type, std::string(), &host_settings);
564 EXPECT_EQ(1U, host_settings.size()); 555 EXPECT_EQ(1U, host_settings.size());
565 } 556 }
566 } 557 }
567 558
568 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) { 559 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) {
569 service_->Init(); 560 service_->Init();
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 new ResettableSettingsSnapshot(profile())); 1071 new ResettableSettingsSnapshot(profile()));
1081 deleted_snapshot->RequestShortcuts(base::Bind(&FeedbackCapture::Fail, 1072 deleted_snapshot->RequestShortcuts(base::Bind(&FeedbackCapture::Fail,
1082 base::Unretained(&capture))); 1073 base::Unretained(&capture)));
1083 deleted_snapshot.reset(); 1074 deleted_snapshot.reset();
1084 // Running remaining tasks shouldn't trigger the callback to be called as 1075 // Running remaining tasks shouldn't trigger the callback to be called as
1085 // |deleted_snapshot| was deleted before it could run. 1076 // |deleted_snapshot| was deleted before it could run.
1086 base::MessageLoop::current()->RunUntilIdle(); 1077 base::MessageLoop::current()->RunUntilIdle();
1087 } 1078 }
1088 1079
1089 } // namespace 1080 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698