| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 10 #include "chrome/browser/prerender/prerender_manager.h" | 10 #include "chrome/browser/prerender/prerender_manager.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 DISALLOW_COPY_AND_ASSIGN(NotificationForwarder); | 59 DISALLOW_COPY_AND_ASSIGN(NotificationForwarder); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 class ContentSettingImageModelTest : public ChromeRenderViewHostTestHarness { | 62 class ContentSettingImageModelTest : public ChromeRenderViewHostTestHarness { |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 TEST_F(ContentSettingImageModelTest, UpdateFromWebContents) { | 65 TEST_F(ContentSettingImageModelTest, UpdateFromWebContents) { |
| 66 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 66 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
| 67 TabSpecificContentSettings* content_settings = | 67 TabSpecificContentSettings* content_settings = |
| 68 TabSpecificContentSettings::FromWebContents(web_contents()); | 68 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 69 scoped_ptr<ContentSettingImageModel> content_setting_image_model = | 69 std::unique_ptr<ContentSettingImageModel> content_setting_image_model = |
| 70 ContentSettingSimpleImageModel::CreateForContentTypeForTesting( | 70 ContentSettingSimpleImageModel::CreateForContentTypeForTesting( |
| 71 CONTENT_SETTINGS_TYPE_IMAGES); | 71 CONTENT_SETTINGS_TYPE_IMAGES); |
| 72 EXPECT_FALSE(content_setting_image_model->is_visible()); | 72 EXPECT_FALSE(content_setting_image_model->is_visible()); |
| 73 EXPECT_TRUE(content_setting_image_model->get_tooltip().empty()); | 73 EXPECT_TRUE(content_setting_image_model->get_tooltip().empty()); |
| 74 | 74 |
| 75 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES); | 75 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES); |
| 76 content_setting_image_model->UpdateFromWebContents(web_contents()); | 76 content_setting_image_model->UpdateFromWebContents(web_contents()); |
| 77 | 77 |
| 78 EXPECT_TRUE(content_setting_image_model->is_visible()); | 78 EXPECT_TRUE(content_setting_image_model->is_visible()); |
| 79 EXPECT_TRUE(HasIcon(*content_setting_image_model)); | 79 EXPECT_TRUE(HasIcon(*content_setting_image_model)); |
| 80 EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); | 80 EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 TEST_F(ContentSettingImageModelTest, RPHUpdateFromWebContents) { | 83 TEST_F(ContentSettingImageModelTest, RPHUpdateFromWebContents) { |
| 84 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 84 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
| 85 scoped_ptr<ContentSettingImageModel> content_setting_image_model = | 85 std::unique_ptr<ContentSettingImageModel> content_setting_image_model = |
| 86 ContentSettingSimpleImageModel::CreateForContentTypeForTesting( | 86 ContentSettingSimpleImageModel::CreateForContentTypeForTesting( |
| 87 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS); | 87 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS); |
| 88 content_setting_image_model->UpdateFromWebContents(web_contents()); | 88 content_setting_image_model->UpdateFromWebContents(web_contents()); |
| 89 EXPECT_FALSE(content_setting_image_model->is_visible()); | 89 EXPECT_FALSE(content_setting_image_model->is_visible()); |
| 90 | 90 |
| 91 TabSpecificContentSettings* content_settings = | 91 TabSpecificContentSettings* content_settings = |
| 92 TabSpecificContentSettings::FromWebContents(web_contents()); | 92 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 93 content_settings->set_pending_protocol_handler( | 93 content_settings->set_pending_protocol_handler( |
| 94 ProtocolHandler::CreateProtocolHandler( | 94 ProtocolHandler::CreateProtocolHandler( |
| 95 "mailto", GURL("http://www.google.com/"))); | 95 "mailto", GURL("http://www.google.com/"))); |
| 96 content_setting_image_model->UpdateFromWebContents(web_contents()); | 96 content_setting_image_model->UpdateFromWebContents(web_contents()); |
| 97 EXPECT_TRUE(content_setting_image_model->is_visible()); | 97 EXPECT_TRUE(content_setting_image_model->is_visible()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 TEST_F(ContentSettingImageModelTest, CookieAccessed) { | 100 TEST_F(ContentSettingImageModelTest, CookieAccessed) { |
| 101 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 101 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
| 102 TabSpecificContentSettings* content_settings = | 102 TabSpecificContentSettings* content_settings = |
| 103 TabSpecificContentSettings::FromWebContents(web_contents()); | 103 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 104 HostContentSettingsMapFactory::GetForProfile(profile()) | 104 HostContentSettingsMapFactory::GetForProfile(profile()) |
| 105 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, | 105 ->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, |
| 106 CONTENT_SETTING_BLOCK); | 106 CONTENT_SETTING_BLOCK); |
| 107 scoped_ptr<ContentSettingImageModel> content_setting_image_model( | 107 std::unique_ptr<ContentSettingImageModel> content_setting_image_model( |
| 108 ContentSettingSimpleImageModel::CreateForContentTypeForTesting( | 108 ContentSettingSimpleImageModel::CreateForContentTypeForTesting( |
| 109 CONTENT_SETTINGS_TYPE_COOKIES)); | 109 CONTENT_SETTINGS_TYPE_COOKIES)); |
| 110 EXPECT_FALSE(content_setting_image_model->is_visible()); | 110 EXPECT_FALSE(content_setting_image_model->is_visible()); |
| 111 EXPECT_TRUE(content_setting_image_model->get_tooltip().empty()); | 111 EXPECT_TRUE(content_setting_image_model->get_tooltip().empty()); |
| 112 | 112 |
| 113 net::CookieOptions options; | 113 net::CookieOptions options; |
| 114 content_settings->OnCookieChanged(GURL("http://google.com"), | 114 content_settings->OnCookieChanged(GURL("http://google.com"), |
| 115 GURL("http://google.com"), | 115 GURL("http://google.com"), |
| 116 "A=B", | 116 "A=B", |
| 117 options, | 117 options, |
| 118 false); | 118 false); |
| 119 content_setting_image_model->UpdateFromWebContents(web_contents()); | 119 content_setting_image_model->UpdateFromWebContents(web_contents()); |
| 120 EXPECT_TRUE(content_setting_image_model->is_visible()); | 120 EXPECT_TRUE(content_setting_image_model->is_visible()); |
| 121 EXPECT_TRUE(HasIcon(*content_setting_image_model)); | 121 EXPECT_TRUE(HasIcon(*content_setting_image_model)); |
| 122 EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); | 122 EXPECT_FALSE(content_setting_image_model->get_tooltip().empty()); |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Regression test for http://crbug.com/161854. | 125 // Regression test for http://crbug.com/161854. |
| 126 TEST_F(ContentSettingImageModelTest, NULLTabSpecificContentSettings) { | 126 TEST_F(ContentSettingImageModelTest, NULLTabSpecificContentSettings) { |
| 127 scoped_ptr<ContentSettingImageModel> content_setting_image_model = | 127 std::unique_ptr<ContentSettingImageModel> content_setting_image_model = |
| 128 ContentSettingSimpleImageModel::CreateForContentTypeForTesting( | 128 ContentSettingSimpleImageModel::CreateForContentTypeForTesting( |
| 129 CONTENT_SETTINGS_TYPE_IMAGES); | 129 CONTENT_SETTINGS_TYPE_IMAGES); |
| 130 NotificationForwarder forwarder(content_setting_image_model.get()); | 130 NotificationForwarder forwarder(content_setting_image_model.get()); |
| 131 // Should not crash. | 131 // Should not crash. |
| 132 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 132 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
| 133 forwarder.clear(); | 133 forwarder.clear(); |
| 134 } | 134 } |
| 135 | 135 |
| 136 } // namespace | 136 } // namespace |
| OLD | NEW |