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

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

Issue 8773035: Content settings: allow scripts on interstitial pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Oops, adding tests killed by the previous patch set. Created 9 years 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
« no previous file with comments | « chrome/renderer/content_settings_observer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 315
316 // Verify that the script was not blocked. 316 // Verify that the script was not blocked.
317 bool was_blocked = false; 317 bool was_blocked = false;
318 for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) { 318 for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) {
319 const IPC::Message* msg = render_thread_->sink().GetMessageAt(i); 319 const IPC::Message* msg = render_thread_->sink().GetMessageAt(i);
320 if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID) 320 if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID)
321 was_blocked = true; 321 was_blocked = true;
322 } 322 }
323 EXPECT_FALSE(was_blocked); 323 EXPECT_FALSE(was_blocked);
324 } 324 }
325
326 TEST_F(ChromeRenderViewTest, ContentSettingsInterstitialPages) {
327 MockContentSettingsObserver mock_observer(view_);
328 // Block scripts.
329 RendererContentSettingRules content_setting_rules;
330 ContentSettingsForOneType& script_setting_rules =
331 content_setting_rules.script_rules;
332 script_setting_rules.push_back(
333 ContentSettingPatternSource(
334 ContentSettingsPattern::Wildcard(),
335 ContentSettingsPattern::Wildcard(),
336 CONTENT_SETTING_BLOCK, "", false));
337 // Block images.
338 ContentSettingsForOneType& image_setting_rules =
339 content_setting_rules.image_rules;
340 image_setting_rules.push_back(
341 ContentSettingPatternSource(
342 ContentSettingsPattern::Wildcard(),
343 ContentSettingsPattern::Wildcard(),
344 CONTENT_SETTING_BLOCK, "", false));
345
346 ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_);
347 observer->SetContentSettingRules(&content_setting_rules);
348 observer->SetAsInterstitial();
349
350 // Load a page which contains a script.
351 std::string html = "<html>"
352 "<head>"
353 "<script src='data:foo'></script>"
354 "</head>"
355 "<body>"
356 "</body>"
357 "</html>";
358 LoadHTML(html.c_str());
359
360 // Verify that the script was allowed.
361 bool was_blocked = false;
362 for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) {
363 const IPC::Message* msg = render_thread_->sink().GetMessageAt(i);
364 if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID)
365 was_blocked = true;
366 }
367 EXPECT_FALSE(was_blocked);
368
369 // Verify that images are allowed.
370 EXPECT_CALL(
371 mock_observer,
372 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, std::string())).Times(0);
373 EXPECT_TRUE(observer->AllowImage(GetMainFrame(), true,
374 mock_observer.image_url_));
375 ::testing::Mock::VerifyAndClearExpectations(&observer);
376 }
OLDNEW
« no previous file with comments | « chrome/renderer/content_settings_observer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698