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

Side by Side Diff: chrome/renderer/content_settings_observer_browsertest.cc

Issue 7831075: Delegating the "are images allowed" decision to renderer. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Updated contentSettings.html. Created 9 years, 2 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) 2011 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/common/content_settings.h" 5 #include "chrome/common/content_settings.h"
6 #include "chrome/common/render_messages.h" 6 #include "chrome/common/render_messages.h"
7 #include "chrome/renderer/content_settings_observer.h" 7 #include "chrome/renderer/content_settings_observer.h"
8 #include "chrome/test/base/chrome_render_view_test.h" 8 #include "chrome/test/base/chrome_render_view_test.h"
9 #include "content/public/renderer/render_view.h" 9 #include "content/public/renderer/render_view.h"
10 #include "ipc/ipc_message_macros.h" 10 #include "ipc/ipc_message_macros.h"
(...skipping 10 matching lines...) Expand all
21 public: 21 public:
22 explicit MockContentSettingsObserver(content::RenderView* render_view); 22 explicit MockContentSettingsObserver(content::RenderView* render_view);
23 23
24 virtual bool Send(IPC::Message* message); 24 virtual bool Send(IPC::Message* message);
25 25
26 MOCK_METHOD2(OnContentBlocked, 26 MOCK_METHOD2(OnContentBlocked,
27 void(ContentSettingsType, const std::string&)); 27 void(ContentSettingsType, const std::string&));
28 28
29 MOCK_METHOD5(OnAllowDOMStorage, 29 MOCK_METHOD5(OnAllowDOMStorage,
30 void(int, const GURL&, const GURL&, bool, IPC::Message*)); 30 void(int, const GURL&, const GURL&, bool, IPC::Message*));
31 GURL image_url_;
32 std::string image_origin_;
31 }; 33 };
32 34
33 MockContentSettingsObserver::MockContentSettingsObserver( 35 MockContentSettingsObserver::MockContentSettingsObserver(
34 content::RenderView* render_view) 36 content::RenderView* render_view)
35 : ContentSettingsObserver(render_view) { 37 : ContentSettingsObserver(render_view),
38 image_url_("http://www.foo.com/image.jpg"),
39 image_origin_("http://www.foo.com") {
36 } 40 }
37 41
38 bool MockContentSettingsObserver::Send(IPC::Message* message) { 42 bool MockContentSettingsObserver::Send(IPC::Message* message) {
39 IPC_BEGIN_MESSAGE_MAP(MockContentSettingsObserver, *message) 43 IPC_BEGIN_MESSAGE_MAP(MockContentSettingsObserver, *message)
40 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked, OnContentBlocked) 44 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked, OnContentBlocked)
41 IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_AllowDOMStorage, 45 IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_AllowDOMStorage,
42 OnAllowDOMStorage) 46 OnAllowDOMStorage)
43 IPC_MESSAGE_UNHANDLED(ADD_FAILURE()) 47 IPC_MESSAGE_UNHANDLED(ADD_FAILURE())
44 IPC_END_MESSAGE_MAP() 48 IPC_END_MESSAGE_MAP()
45 49
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 EXPECT_TRUE(observer->plugins_temporarily_allowed()); 159 EXPECT_TRUE(observer->plugins_temporarily_allowed());
156 160
157 // Simulate a navigation within the page. 161 // Simulate a navigation within the page.
158 DidNavigateWithinPage(GetMainFrame(), true); 162 DidNavigateWithinPage(GetMainFrame(), true);
159 EXPECT_TRUE(observer->plugins_temporarily_allowed()); 163 EXPECT_TRUE(observer->plugins_temporarily_allowed());
160 164
161 // Navigate to a different page. 165 // Navigate to a different page.
162 LoadHTML("<html>Bar</html>"); 166 LoadHTML("<html>Bar</html>");
163 EXPECT_FALSE(observer->plugins_temporarily_allowed()); 167 EXPECT_FALSE(observer->plugins_temporarily_allowed());
164 } 168 }
169
170 TEST_F(ChromeRenderViewTest, ImagesBlockedByDefault) {
171 MockContentSettingsObserver mock_observer(view_);
172
173 // Load some HTML.
174 LoadHTML("<html>Foo</html>");
175
176 // Set the default image blocking setting.
177 ContentSettingsForOneType image_setting_rules;
178 image_setting_rules.push_back(
179 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
180 ContentSettingsPattern::Wildcard(),
181 CONTENT_SETTING_BLOCK,
182 "",
183 false));
184
185 ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_);
186 observer->SetImageSettingRules(&image_setting_rules);
187 EXPECT_CALL(mock_observer,
188 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
189 EXPECT_FALSE(observer->AllowImage(GetMainFrame(),
190 true, mock_observer.image_url_));
191 ::testing::Mock::VerifyAndClearExpectations(&observer);
192
193 // Create an exception which allows the image.
194 image_setting_rules.insert(
195 image_setting_rules.begin(),
196 ContentSettingPatternSource(
197 ContentSettingsPattern::Wildcard(),
198 ContentSettingsPattern::FromString(mock_observer.image_origin_),
199 CONTENT_SETTING_ALLOW,
200 "",
201 false));
202
203 EXPECT_CALL(
204 mock_observer,
205 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string())).Times(0);
206 EXPECT_TRUE(observer->AllowImage(GetMainFrame(), true,
207 mock_observer.image_url_));
208 ::testing::Mock::VerifyAndClearExpectations(&observer);
209 }
210
211 TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) {
212 MockContentSettingsObserver mock_observer(view_);
213
214 // Load some HTML.
215 LoadHTML("<html>Foo</html>");
216
217 // Set the default image blocking setting.
218 ContentSettingsForOneType image_setting_rules;
219 image_setting_rules.push_back(
220 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(),
221 ContentSettingsPattern::Wildcard(),
222 CONTENT_SETTING_ALLOW,
223 "",
224 false));
225
226 ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_);
227 observer->SetImageSettingRules(&image_setting_rules);
228 EXPECT_CALL(
229 mock_observer,
230 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string())).Times(0);
231 EXPECT_TRUE(observer->AllowImage(GetMainFrame(), true,
232 mock_observer.image_url_));
233 ::testing::Mock::VerifyAndClearExpectations(&observer);
234
235 // Create an exception which blocks the image.
236 image_setting_rules.insert(
237 image_setting_rules.begin(),
238 ContentSettingPatternSource(
239 ContentSettingsPattern::Wildcard(),
240 ContentSettingsPattern::FromString(mock_observer.image_origin_),
241 CONTENT_SETTING_BLOCK,
242 "",
243 false));
244 EXPECT_CALL(mock_observer,
245 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
246 EXPECT_FALSE(observer->AllowImage(GetMainFrame(),
247 true, mock_observer.image_url_));
248 ::testing::Mock::VerifyAndClearExpectations(&observer);
249 }
OLDNEW
« chrome/renderer/content_settings_observer.cc ('K') | « chrome/renderer/content_settings_observer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698