OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/tab_contents/tab_specific_content_settings.h" |
| 6 |
| 7 #include "chrome/test/testing_profile.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace { |
| 11 class TestContentSettingsDelegate |
| 12 : public TabSpecificContentSettings::Delegate { |
| 13 public: |
| 14 TestContentSettingsDelegate() : settings_changed_(false) {} |
| 15 virtual ~TestContentSettingsDelegate() {} |
| 16 |
| 17 void Reset() { settings_changed_ = false; } |
| 18 |
| 19 bool SettingsChanged() { return settings_changed_; } |
| 20 |
| 21 // TabSpecificContentSettings::Delegate implementation. |
| 22 virtual void OnContentSettingsChange() { settings_changed_ = true; } |
| 23 |
| 24 private: |
| 25 bool settings_changed_; |
| 26 |
| 27 DISALLOW_COPY_AND_ASSIGN(TestContentSettingsDelegate); |
| 28 }; |
| 29 } // namespace |
| 30 |
| 31 TEST(TabSpecificContentSettingsTest, BlockedContent) { |
| 32 TestContentSettingsDelegate test_delegate; |
| 33 TestingProfile profile; |
| 34 TabSpecificContentSettings content_settings(&test_delegate, &profile); |
| 35 |
| 36 // Check that after initializing, nothing is blocked. |
| 37 EXPECT_FALSE(content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)); |
| 38 EXPECT_FALSE( |
| 39 content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); |
| 40 EXPECT_FALSE( |
| 41 content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 42 EXPECT_FALSE( |
| 43 content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 44 EXPECT_FALSE(content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS)); |
| 45 |
| 46 // Set a cookie, block access to images, block a popup. |
| 47 content_settings.OnCookieAccessed(GURL("http://google.com"), "A=B", false); |
| 48 EXPECT_FALSE(test_delegate.SettingsChanged()); |
| 49 test_delegate.Reset(); |
| 50 content_settings.OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES); |
| 51 EXPECT_TRUE(test_delegate.SettingsChanged()); |
| 52 test_delegate.Reset(); |
| 53 content_settings.SetPopupsBlocked(true); |
| 54 EXPECT_TRUE(test_delegate.SettingsChanged()); |
| 55 test_delegate.Reset(); |
| 56 |
| 57 // Check that only the respective content types are affected. |
| 58 EXPECT_TRUE(content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)); |
| 59 EXPECT_FALSE( |
| 60 content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); |
| 61 EXPECT_FALSE( |
| 62 content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 63 EXPECT_FALSE( |
| 64 content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 65 EXPECT_TRUE(content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS)); |
| 66 |
| 67 // Reset blocked content settings. |
| 68 content_settings.ClearBlockedContentSettings(); |
| 69 EXPECT_TRUE(test_delegate.SettingsChanged()); |
| 70 EXPECT_FALSE(content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)); |
| 71 EXPECT_FALSE( |
| 72 content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_JAVASCRIPT)); |
| 73 EXPECT_FALSE( |
| 74 content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 75 EXPECT_FALSE( |
| 76 content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 77 EXPECT_FALSE(content_settings.IsContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS)); |
| 78 } |
OLD | NEW |