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

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

Issue 10542010: TabContentsWrapper -> TabContents, part 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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) 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/auto_reset.h" 5 #include "base/auto_reset.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "chrome/browser/content_settings/host_content_settings_map.h" 7 #include "chrome/browser/content_settings/host_content_settings_map.h"
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 10 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
12 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" 12 #include "chrome/browser/ui/tab_contents/test_tab_contents.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/test_browser_thread.h" 16 #include "content/public/test/test_browser_thread.h"
17 #include "content/public/test/web_contents_tester.h" 17 #include "content/public/test/web_contents_tester.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using content::BrowserThread; 20 using content::BrowserThread;
21 using content::WebContentsTester; 21 using content::WebContentsTester;
22 22
23 class ContentSettingBubbleModelTest : public TabContentsWrapperTestHarness { 23 class ContentSettingBubbleModelTest : public TabContentsTestHarness {
24 protected: 24 protected:
25 ContentSettingBubbleModelTest() 25 ContentSettingBubbleModelTest()
26 : ui_thread_(BrowserThread::UI, MessageLoop::current()) { 26 : ui_thread_(BrowserThread::UI, MessageLoop::current()) {
27 } 27 }
28 28
29 void CheckGeolocationBubble(size_t expected_domains, 29 void CheckGeolocationBubble(size_t expected_domains,
30 bool expect_clear_link, 30 bool expect_clear_link,
31 bool expect_reload_hint) { 31 bool expect_reload_hint) {
32 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 32 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
33 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 33 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
34 NULL, contents_wrapper(), profile(), 34 NULL, tab_contents(), profile(),
35 CONTENT_SETTINGS_TYPE_GEOLOCATION)); 35 CONTENT_SETTINGS_TYPE_GEOLOCATION));
36 const ContentSettingBubbleModel::BubbleContent& bubble_content = 36 const ContentSettingBubbleModel::BubbleContent& bubble_content =
37 content_setting_bubble_model->bubble_content(); 37 content_setting_bubble_model->bubble_content();
38 EXPECT_TRUE(bubble_content.title.empty()); 38 EXPECT_TRUE(bubble_content.title.empty());
39 EXPECT_TRUE(bubble_content.radio_group.radio_items.empty()); 39 EXPECT_TRUE(bubble_content.radio_group.radio_items.empty());
40 EXPECT_TRUE(bubble_content.popup_items.empty()); 40 EXPECT_TRUE(bubble_content.popup_items.empty());
41 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size()); 41 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size());
42 EXPECT_NE(expect_clear_link || expect_reload_hint, 42 EXPECT_NE(expect_clear_link || expect_reload_hint,
43 bubble_content.custom_link.empty()); 43 bubble_content.custom_link.empty());
44 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled); 44 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled);
45 EXPECT_FALSE(bubble_content.manage_link.empty()); 45 EXPECT_FALSE(bubble_content.manage_link.empty());
46 } 46 }
47 47
48 content::TestBrowserThread ui_thread_; 48 content::TestBrowserThread ui_thread_;
49 }; 49 };
50 50
51 TEST_F(ContentSettingBubbleModelTest, ImageRadios) { 51 TEST_F(ContentSettingBubbleModelTest, ImageRadios) {
52 TabSpecificContentSettings* content_settings = 52 TabSpecificContentSettings* content_settings =
53 contents_wrapper()->content_settings(); 53 tab_contents()->content_settings();
54 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, 54 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES,
55 std::string()); 55 std::string());
56 56
57 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 57 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
58 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 58 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
59 NULL, contents_wrapper(), profile(), 59 NULL, tab_contents(), profile(), CONTENT_SETTINGS_TYPE_IMAGES));
60 CONTENT_SETTINGS_TYPE_IMAGES));
61 const ContentSettingBubbleModel::BubbleContent& bubble_content = 60 const ContentSettingBubbleModel::BubbleContent& bubble_content =
62 content_setting_bubble_model->bubble_content(); 61 content_setting_bubble_model->bubble_content();
63 EXPECT_FALSE(bubble_content.title.empty()); 62 EXPECT_FALSE(bubble_content.title.empty());
64 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); 63 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
65 EXPECT_EQ(0, bubble_content.radio_group.default_item); 64 EXPECT_EQ(0, bubble_content.radio_group.default_item);
66 EXPECT_TRUE(bubble_content.custom_link.empty()); 65 EXPECT_TRUE(bubble_content.custom_link.empty());
67 EXPECT_FALSE(bubble_content.manage_link.empty()); 66 EXPECT_FALSE(bubble_content.manage_link.empty());
68 } 67 }
69 68
70 TEST_F(ContentSettingBubbleModelTest, Cookies) { 69 TEST_F(ContentSettingBubbleModelTest, Cookies) {
71 TabSpecificContentSettings* content_settings = 70 TabSpecificContentSettings* content_settings =
72 contents_wrapper()->content_settings(); 71 tab_contents()->content_settings();
73 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, 72 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES,
74 std::string()); 73 std::string());
75 74
76 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 75 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
77 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 76 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
78 NULL, contents_wrapper(), profile(), 77 NULL, tab_contents(), profile(), CONTENT_SETTINGS_TYPE_COOKIES));
79 CONTENT_SETTINGS_TYPE_COOKIES));
80 const ContentSettingBubbleModel::BubbleContent& bubble_content = 78 const ContentSettingBubbleModel::BubbleContent& bubble_content =
81 content_setting_bubble_model->bubble_content(); 79 content_setting_bubble_model->bubble_content();
82 EXPECT_FALSE(bubble_content.title.empty()); 80 EXPECT_FALSE(bubble_content.title.empty());
83 EXPECT_FALSE(bubble_content.radio_group.radio_items.empty()); 81 EXPECT_FALSE(bubble_content.radio_group.radio_items.empty());
84 EXPECT_FALSE(bubble_content.custom_link.empty()); 82 EXPECT_FALSE(bubble_content.custom_link.empty());
85 EXPECT_TRUE(bubble_content.custom_link_enabled); 83 EXPECT_TRUE(bubble_content.custom_link_enabled);
86 EXPECT_FALSE(bubble_content.manage_link.empty()); 84 EXPECT_FALSE(bubble_content.manage_link.empty());
87 } 85 }
88 86
89 TEST_F(ContentSettingBubbleModelTest, Plugins) { 87 TEST_F(ContentSettingBubbleModelTest, Plugins) {
90 TabSpecificContentSettings* content_settings = 88 TabSpecificContentSettings* content_settings =
91 contents_wrapper()->content_settings(); 89 tab_contents()->content_settings();
92 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, 90 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS,
93 std::string()); 91 std::string());
94 92
95 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 93 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
96 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 94 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
97 NULL, contents_wrapper(), profile(), 95 NULL, tab_contents(), profile(),
98 CONTENT_SETTINGS_TYPE_PLUGINS)); 96 CONTENT_SETTINGS_TYPE_PLUGINS));
99 const ContentSettingBubbleModel::BubbleContent& bubble_content = 97 const ContentSettingBubbleModel::BubbleContent& bubble_content =
100 content_setting_bubble_model->bubble_content(); 98 content_setting_bubble_model->bubble_content();
101 EXPECT_FALSE(bubble_content.title.empty()); 99 EXPECT_FALSE(bubble_content.title.empty());
102 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); 100 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
103 EXPECT_FALSE(bubble_content.custom_link.empty()); 101 EXPECT_FALSE(bubble_content.custom_link.empty());
104 EXPECT_TRUE(bubble_content.custom_link_enabled); 102 EXPECT_TRUE(bubble_content.custom_link_enabled);
105 EXPECT_FALSE(bubble_content.manage_link.empty()); 103 EXPECT_FALSE(bubble_content.manage_link.empty());
106 } 104 }
107 105
(...skipping 16 matching lines...) Expand all
124 CONTENT_SETTINGS_TYPE_PLUGINS, 122 CONTENT_SETTINGS_TYPE_PLUGINS,
125 fooPlugin, 123 fooPlugin,
126 CONTENT_SETTING_ALLOW); 124 CONTENT_SETTING_ALLOW);
127 map->AddExceptionForURL(url, 125 map->AddExceptionForURL(url,
128 url, 126 url,
129 CONTENT_SETTINGS_TYPE_PLUGINS, 127 CONTENT_SETTINGS_TYPE_PLUGINS,
130 barPlugin, 128 barPlugin,
131 CONTENT_SETTING_ASK); 129 CONTENT_SETTING_ASK);
132 130
133 TabSpecificContentSettings* content_settings = 131 TabSpecificContentSettings* content_settings =
134 contents_wrapper()->content_settings(); 132 tab_contents()->content_settings();
135 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, 133 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS,
136 fooPlugin); 134 fooPlugin);
137 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, 135 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS,
138 barPlugin); 136 barPlugin);
139 137
140 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 138 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
141 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 139 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
142 NULL, contents_wrapper(), profile(), 140 NULL, tab_contents(), profile(), CONTENT_SETTINGS_TYPE_PLUGINS));
143 CONTENT_SETTINGS_TYPE_PLUGINS));
144 const ContentSettingBubbleModel::BubbleContent& bubble_content = 141 const ContentSettingBubbleModel::BubbleContent& bubble_content =
145 content_setting_bubble_model->bubble_content(); 142 content_setting_bubble_model->bubble_content();
146 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); 143 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
147 EXPECT_EQ(1, bubble_content.radio_group.default_item); 144 EXPECT_EQ(1, bubble_content.radio_group.default_item);
148 145
149 content_setting_bubble_model->OnRadioClicked(0); 146 content_setting_bubble_model->OnRadioClicked(0);
150 // Nothing should have changed. 147 // Nothing should have changed.
151 EXPECT_EQ(CONTENT_SETTING_ALLOW, 148 EXPECT_EQ(CONTENT_SETTING_ALLOW,
152 map->GetContentSetting(url, 149 map->GetContentSetting(url,
153 url, 150 url,
(...skipping 19 matching lines...) Expand all
173 barPlugin)); 170 barPlugin));
174 } 171 }
175 172
176 TEST_F(ContentSettingBubbleModelTest, Geolocation) { 173 TEST_F(ContentSettingBubbleModelTest, Geolocation) {
177 const GURL page_url("http://toplevel.example/"); 174 const GURL page_url("http://toplevel.example/");
178 const GURL frame1_url("http://host1.example/"); 175 const GURL frame1_url("http://host1.example/");
179 const GURL frame2_url("http://host2.example:999/"); 176 const GURL frame2_url("http://host2.example:999/");
180 177
181 NavigateAndCommit(page_url); 178 NavigateAndCommit(page_url);
182 TabSpecificContentSettings* content_settings = 179 TabSpecificContentSettings* content_settings =
183 contents_wrapper()->content_settings(); 180 tab_contents()->content_settings();
184 181
185 // One permitted frame, but not in the content map: requires reload. 182 // One permitted frame, but not in the content map: requires reload.
186 content_settings->OnGeolocationPermissionSet(frame1_url, true); 183 content_settings->OnGeolocationPermissionSet(frame1_url, true);
187 CheckGeolocationBubble(1, false, true); 184 CheckGeolocationBubble(1, false, true);
188 185
189 // Add it to the content map, should now have a clear link. 186 // Add it to the content map, should now have a clear link.
190 HostContentSettingsMap* setting_map = 187 HostContentSettingsMap* setting_map =
191 profile()->GetHostContentSettingsMap(); 188 profile()->GetHostContentSettingsMap();
192 setting_map->SetContentSetting( 189 setting_map->SetContentSetting(
193 ContentSettingsPattern::FromURLNoWildcard(frame1_url), 190 ContentSettingsPattern::FromURLNoWildcard(frame1_url),
(...skipping 16 matching lines...) Expand all
210 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( 207 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
211 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK); 208 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK);
212 CheckGeolocationBubble(2, true, false); 209 CheckGeolocationBubble(2, true, false);
213 } 210 }
214 211
215 TEST_F(ContentSettingBubbleModelTest, FileURL) { 212 TEST_F(ContentSettingBubbleModelTest, FileURL) {
216 std::string file_url("file:///tmp/test.html"); 213 std::string file_url("file:///tmp/test.html");
217 NavigateAndCommit(GURL(file_url)); 214 NavigateAndCommit(GURL(file_url));
218 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 215 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
219 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 216 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
220 NULL, contents_wrapper(), profile(), 217 NULL, tab_contents(), profile(),
221 CONTENT_SETTINGS_TYPE_IMAGES)); 218 CONTENT_SETTINGS_TYPE_IMAGES));
222 std::string title = 219 std::string title =
223 content_setting_bubble_model->bubble_content().radio_group.radio_items[0]; 220 content_setting_bubble_model->bubble_content().radio_group.radio_items[0];
224 ASSERT_NE(std::string::npos, title.find(file_url)); 221 ASSERT_NE(std::string::npos, title.find(file_url));
225 } 222 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698