| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/content_setting_bubble_model.h" | 5 #include "chrome/browser/content_setting_bubble_model.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profile.h" | 7 #include "chrome/browser/profile.h" |
| 8 #include "chrome/browser/renderer_host/test/test_render_view_host.h" | 8 #include "chrome/browser/renderer_host/test/test_render_view_host.h" |
| 9 #include "chrome/browser/tab_contents/test_tab_contents.h" | 9 #include "chrome/browser/tab_contents/test_tab_contents.h" |
| 10 #include "chrome/test/testing_profile.h" | 10 #include "chrome/test/testing_profile.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 else | 36 else |
| 37 EXPECT_EQ(std::string(), bubble_content.clear_link); | 37 EXPECT_EQ(std::string(), bubble_content.clear_link); |
| 38 EXPECT_NE(std::string(), bubble_content.manage_link); | 38 EXPECT_NE(std::string(), bubble_content.manage_link); |
| 39 EXPECT_EQ(std::string(), bubble_content.title); | 39 EXPECT_EQ(std::string(), bubble_content.title); |
| 40 } | 40 } |
| 41 | 41 |
| 42 ChromeThread ui_thread_; | 42 ChromeThread ui_thread_; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 TEST_F(ContentSettingBubbleModelTest, ImageRadios) { | 45 TEST_F(ContentSettingBubbleModelTest, ImageRadios) { |
| 46 RenderViewHostDelegate::ContentSettings* render_view_host_delegate = | 46 TabSpecificContentSettings* content_settings = |
| 47 contents(); | 47 contents()->GetTabSpecificContentSettings(); |
| 48 render_view_host_delegate->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES); | 48 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES); |
| 49 | 49 |
| 50 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 50 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 51 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 51 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 52 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_IMAGES)); | 52 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_IMAGES)); |
| 53 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 53 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 54 content_setting_bubble_model->bubble_content(); | 54 content_setting_bubble_model->bubble_content(); |
| 55 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); | 55 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); |
| 56 EXPECT_EQ(0, bubble_content.radio_group.default_item); | 56 EXPECT_EQ(0, bubble_content.radio_group.default_item); |
| 57 EXPECT_NE(std::string(), bubble_content.manage_link); | 57 EXPECT_NE(std::string(), bubble_content.manage_link); |
| 58 EXPECT_NE(std::string(), bubble_content.title); | 58 EXPECT_NE(std::string(), bubble_content.title); |
| 59 } | 59 } |
| 60 | 60 |
| 61 TEST_F(ContentSettingBubbleModelTest, Cookies) { | 61 TEST_F(ContentSettingBubbleModelTest, Cookies) { |
| 62 RenderViewHostDelegate::ContentSettings* render_view_host_delegate = | 62 TabSpecificContentSettings* content_settings = |
| 63 contents(); | 63 contents()->GetTabSpecificContentSettings(); |
| 64 render_view_host_delegate->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); | 64 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); |
| 65 | 65 |
| 66 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 66 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 67 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 67 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 68 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_COOKIES)); | 68 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_COOKIES)); |
| 69 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 69 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 70 content_setting_bubble_model->bubble_content(); | 70 content_setting_bubble_model->bubble_content(); |
| 71 EXPECT_EQ(0U, bubble_content.radio_group.radio_items.size()); | 71 EXPECT_EQ(0U, bubble_content.radio_group.radio_items.size()); |
| 72 EXPECT_NE(std::string(), bubble_content.manage_link); | 72 EXPECT_NE(std::string(), bubble_content.manage_link); |
| 73 EXPECT_NE(std::string(), bubble_content.title); | 73 EXPECT_NE(std::string(), bubble_content.title); |
| 74 } | 74 } |
| 75 | 75 |
| 76 TEST_F(ContentSettingBubbleModelTest, Geolocation) { | 76 TEST_F(ContentSettingBubbleModelTest, Geolocation) { |
| 77 const GURL page_url("http://toplevel.example/"); | 77 const GURL page_url("http://toplevel.example/"); |
| 78 const GURL frame1_url("http://host1.example/"); | 78 const GURL frame1_url("http://host1.example/"); |
| 79 const GURL frame2_url("http://host2.example:999/"); | 79 const GURL frame2_url("http://host2.example:999/"); |
| 80 | 80 |
| 81 NavigateAndCommit(page_url); | 81 NavigateAndCommit(page_url); |
| 82 RenderViewHostDelegate::ContentSettings* render_view_host_delegate = | 82 TabSpecificContentSettings* content_settings = |
| 83 contents(); | 83 contents()->GetTabSpecificContentSettings(); |
| 84 | 84 |
| 85 // One permitted frame, but not in the content map: requires reload. | 85 // One permitted frame, but not in the content map: requires reload. |
| 86 render_view_host_delegate->OnGeolocationPermissionSet(frame1_url, true); | 86 content_settings->OnGeolocationPermissionSet(frame1_url, true); |
| 87 CheckGeolocationBubble(1, false, true); | 87 CheckGeolocationBubble(1, false, true); |
| 88 | 88 |
| 89 // Add it to the content map, should now have a clear link. | 89 // Add it to the content map, should now have a clear link. |
| 90 GeolocationContentSettingsMap* setting_map = | 90 GeolocationContentSettingsMap* setting_map = |
| 91 profile_->GetGeolocationContentSettingsMap(); | 91 profile_->GetGeolocationContentSettingsMap(); |
| 92 setting_map->SetContentSetting(frame1_url, page_url, CONTENT_SETTING_ALLOW); | 92 setting_map->SetContentSetting(frame1_url, page_url, CONTENT_SETTING_ALLOW); |
| 93 CheckGeolocationBubble(1, true, false); | 93 CheckGeolocationBubble(1, true, false); |
| 94 | 94 |
| 95 // Change the default to allow: no message needed. | 95 // Change the default to allow: no message needed. |
| 96 setting_map->SetDefaultContentSetting(CONTENT_SETTING_ALLOW); | 96 setting_map->SetDefaultContentSetting(CONTENT_SETTING_ALLOW); |
| 97 CheckGeolocationBubble(1, false, false); | 97 CheckGeolocationBubble(1, false, false); |
| 98 | 98 |
| 99 // Second frame denied, but not stored in the content map: requires reload. | 99 // Second frame denied, but not stored in the content map: requires reload. |
| 100 render_view_host_delegate->OnGeolocationPermissionSet(frame2_url, false); | 100 content_settings->OnGeolocationPermissionSet(frame2_url, false); |
| 101 CheckGeolocationBubble(2, false, true); | 101 CheckGeolocationBubble(2, false, true); |
| 102 | 102 |
| 103 // Change the default to block: offer a clear link for the persisted frame 1. | 103 // Change the default to block: offer a clear link for the persisted frame 1. |
| 104 setting_map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK); | 104 setting_map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK); |
| 105 CheckGeolocationBubble(2, true, false); | 105 CheckGeolocationBubble(2, true, false); |
| 106 } | 106 } |
| OLD | NEW |