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

Side by Side Diff: chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc

Issue 6854035: Move blocked content from TabContents to TabContentsWrapper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
6
7 #include "base/auto_reset.h" 5 #include "base/auto_reset.h"
8 #include "base/command_line.h" 6 #include "base/command_line.h"
9 #include "chrome/browser/content_settings/host_content_settings_map.h" 7 #include "chrome/browser/content_settings/host_content_settings_map.h"
10 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" 9 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
10 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
11 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/testing_profile.h" 13 #include "chrome/test/testing_profile.h"
14 #include "content/browser/browser_thread.h" 14 #include "content/browser/browser_thread.h"
15 #include "content/browser/renderer_host/test_render_view_host.h"
16 #include "content/browser/tab_contents/test_tab_contents.h" 15 #include "content/browser/tab_contents/test_tab_contents.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 17
19 class ContentSettingBubbleModelTest : public RenderViewHostTestHarness { 18 class ContentSettingBubbleModelTest : public TabContentsWrapperTestHarness {
20 protected: 19 protected:
21 ContentSettingBubbleModelTest() 20 ContentSettingBubbleModelTest()
22 : ui_thread_(BrowserThread::UI, MessageLoop::current()) { 21 : ui_thread_(BrowserThread::UI, MessageLoop::current()) {
23 } 22 }
24 23
25 void CheckGeolocationBubble(size_t expected_domains, 24 void CheckGeolocationBubble(size_t expected_domains,
26 bool expect_clear_link, 25 bool expect_clear_link,
27 bool expect_reload_hint) { 26 bool expect_reload_hint) {
28 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 27 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
29 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 28 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
30 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_GEOLOCATION)); 29 contents_wrapper(), profile_.get(),
30 CONTENT_SETTINGS_TYPE_GEOLOCATION));
31 const ContentSettingBubbleModel::BubbleContent& bubble_content = 31 const ContentSettingBubbleModel::BubbleContent& bubble_content =
32 content_setting_bubble_model->bubble_content(); 32 content_setting_bubble_model->bubble_content();
33 EXPECT_TRUE(bubble_content.title.empty()); 33 EXPECT_TRUE(bubble_content.title.empty());
34 EXPECT_TRUE(bubble_content.radio_group.radio_items.empty()); 34 EXPECT_TRUE(bubble_content.radio_group.radio_items.empty());
35 EXPECT_TRUE(bubble_content.popup_items.empty()); 35 EXPECT_TRUE(bubble_content.popup_items.empty());
36 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size()); 36 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size());
37 EXPECT_NE(expect_clear_link || expect_reload_hint, 37 EXPECT_NE(expect_clear_link || expect_reload_hint,
38 bubble_content.custom_link.empty()); 38 bubble_content.custom_link.empty());
39 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled); 39 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled);
40 EXPECT_FALSE(bubble_content.manage_link.empty()); 40 EXPECT_FALSE(bubble_content.manage_link.empty());
41 } 41 }
42 42
43 BrowserThread ui_thread_; 43 BrowserThread ui_thread_;
44 }; 44 };
45 45
46 TEST_F(ContentSettingBubbleModelTest, ImageRadios) { 46 TEST_F(ContentSettingBubbleModelTest, ImageRadios) {
47 TabSpecificContentSettings* content_settings = 47 TabSpecificContentSettings* content_settings =
48 contents()->GetTabSpecificContentSettings(); 48 contents()->GetTabSpecificContentSettings();
49 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, 49 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES,
50 std::string()); 50 std::string());
51 51
52 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 52 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
53 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 53 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
54 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_IMAGES)); 54 contents_wrapper(), profile_.get(), CONTENT_SETTINGS_TYPE_IMAGES));
55 const ContentSettingBubbleModel::BubbleContent& bubble_content = 55 const ContentSettingBubbleModel::BubbleContent& bubble_content =
56 content_setting_bubble_model->bubble_content(); 56 content_setting_bubble_model->bubble_content();
57 EXPECT_FALSE(bubble_content.title.empty()); 57 EXPECT_FALSE(bubble_content.title.empty());
58 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); 58 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
59 EXPECT_EQ(0, bubble_content.radio_group.default_item); 59 EXPECT_EQ(0, bubble_content.radio_group.default_item);
60 EXPECT_TRUE(bubble_content.custom_link.empty()); 60 EXPECT_TRUE(bubble_content.custom_link.empty());
61 EXPECT_FALSE(bubble_content.manage_link.empty()); 61 EXPECT_FALSE(bubble_content.manage_link.empty());
62 } 62 }
63 63
64 TEST_F(ContentSettingBubbleModelTest, Cookies) { 64 TEST_F(ContentSettingBubbleModelTest, Cookies) {
65 TabSpecificContentSettings* content_settings = 65 TabSpecificContentSettings* content_settings =
66 contents()->GetTabSpecificContentSettings(); 66 contents()->GetTabSpecificContentSettings();
67 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, 67 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES,
68 std::string()); 68 std::string());
69 69
70 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 70 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
71 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 71 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
72 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_COOKIES)); 72 contents_wrapper(), profile_.get(), CONTENT_SETTINGS_TYPE_COOKIES));
73 const ContentSettingBubbleModel::BubbleContent& bubble_content = 73 const ContentSettingBubbleModel::BubbleContent& bubble_content =
74 content_setting_bubble_model->bubble_content(); 74 content_setting_bubble_model->bubble_content();
75 EXPECT_FALSE(bubble_content.title.empty()); 75 EXPECT_FALSE(bubble_content.title.empty());
76 EXPECT_FALSE(bubble_content.radio_group.radio_items.empty()); 76 EXPECT_FALSE(bubble_content.radio_group.radio_items.empty());
77 EXPECT_FALSE(bubble_content.custom_link.empty()); 77 EXPECT_FALSE(bubble_content.custom_link.empty());
78 EXPECT_TRUE(bubble_content.custom_link_enabled); 78 EXPECT_TRUE(bubble_content.custom_link_enabled);
79 EXPECT_FALSE(bubble_content.manage_link.empty()); 79 EXPECT_FALSE(bubble_content.manage_link.empty());
80 } 80 }
81 81
82 TEST_F(ContentSettingBubbleModelTest, Plugins) { 82 TEST_F(ContentSettingBubbleModelTest, Plugins) {
83 TabSpecificContentSettings* content_settings = 83 TabSpecificContentSettings* content_settings =
84 contents()->GetTabSpecificContentSettings(); 84 contents()->GetTabSpecificContentSettings();
85 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, 85 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS,
86 std::string()); 86 std::string());
87 87
88 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 88 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
89 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 89 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
90 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_PLUGINS)); 90 contents_wrapper(), profile_.get(), CONTENT_SETTINGS_TYPE_PLUGINS));
91 const ContentSettingBubbleModel::BubbleContent& bubble_content = 91 const ContentSettingBubbleModel::BubbleContent& bubble_content =
92 content_setting_bubble_model->bubble_content(); 92 content_setting_bubble_model->bubble_content();
93 EXPECT_FALSE(bubble_content.title.empty()); 93 EXPECT_FALSE(bubble_content.title.empty());
94 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); 94 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
95 EXPECT_FALSE(bubble_content.custom_link.empty()); 95 EXPECT_FALSE(bubble_content.custom_link.empty());
96 EXPECT_TRUE(bubble_content.custom_link_enabled); 96 EXPECT_TRUE(bubble_content.custom_link_enabled);
97 EXPECT_FALSE(bubble_content.manage_link.empty()); 97 EXPECT_FALSE(bubble_content.manage_link.empty());
98 } 98 }
99 99
100 TEST_F(ContentSettingBubbleModelTest, MultiplePlugins) { 100 TEST_F(ContentSettingBubbleModelTest, MultiplePlugins) {
(...skipping 17 matching lines...) Expand all
118 118
119 TabSpecificContentSettings* content_settings = 119 TabSpecificContentSettings* content_settings =
120 contents()->GetTabSpecificContentSettings(); 120 contents()->GetTabSpecificContentSettings();
121 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, 121 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS,
122 fooPlugin); 122 fooPlugin);
123 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, 123 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS,
124 barPlugin); 124 barPlugin);
125 125
126 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 126 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
127 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 127 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
128 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_PLUGINS)); 128 contents_wrapper(), profile_.get(), CONTENT_SETTINGS_TYPE_PLUGINS));
129 const ContentSettingBubbleModel::BubbleContent& bubble_content = 129 const ContentSettingBubbleModel::BubbleContent& bubble_content =
130 content_setting_bubble_model->bubble_content(); 130 content_setting_bubble_model->bubble_content();
131 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); 131 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
132 EXPECT_EQ(1, bubble_content.radio_group.default_item); 132 EXPECT_EQ(1, bubble_content.radio_group.default_item);
133 133
134 content_setting_bubble_model->OnRadioClicked(0); 134 content_setting_bubble_model->OnRadioClicked(0);
135 // Nothing should have changed. 135 // Nothing should have changed.
136 EXPECT_EQ(CONTENT_SETTING_ALLOW, 136 EXPECT_EQ(CONTENT_SETTING_ALLOW,
137 map->GetContentSetting(url, 137 map->GetContentSetting(url,
138 CONTENT_SETTINGS_TYPE_PLUGINS, 138 CONTENT_SETTINGS_TYPE_PLUGINS,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 // Change the default to block: offer a clear link for the persisted frame 1. 184 // Change the default to block: offer a clear link for the persisted frame 1.
185 setting_map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK); 185 setting_map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK);
186 CheckGeolocationBubble(2, true, false); 186 CheckGeolocationBubble(2, true, false);
187 } 187 }
188 188
189 TEST_F(ContentSettingBubbleModelTest, FileURL) { 189 TEST_F(ContentSettingBubbleModelTest, FileURL) {
190 std::string file_url("file:///tmp/test.html"); 190 std::string file_url("file:///tmp/test.html");
191 NavigateAndCommit(GURL(file_url)); 191 NavigateAndCommit(GURL(file_url));
192 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 192 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
193 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 193 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
194 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_IMAGES)); 194 contents_wrapper(), profile_.get(), CONTENT_SETTINGS_TYPE_IMAGES));
195 std::string title = 195 std::string title =
196 content_setting_bubble_model->bubble_content().radio_group.radio_items[0]; 196 content_setting_bubble_model->bubble_content().radio_group.radio_items[0];
197 ASSERT_NE(std::string::npos, title.find(file_url)); 197 ASSERT_NE(std::string::npos, title.find(file_url));
198 } 198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698