| OLD | NEW |
| 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/render_view_test.h" | 8 #include "chrome/test/base/render_view_test.h" |
| 9 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
| 10 #include "ipc/ipc_message_macros.h" | 10 #include "ipc/ipc_message_macros.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 void(int, const GURL&, const GURL&, bool, IPC::Message*)); | 30 void(int, const GURL&, const GURL&, bool, IPC::Message*)); |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 MockContentSettingsObserver::MockContentSettingsObserver( | 33 MockContentSettingsObserver::MockContentSettingsObserver( |
| 34 RenderView* render_view) | 34 RenderView* render_view) |
| 35 : ContentSettingsObserver(render_view) { | 35 : ContentSettingsObserver(render_view) { |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool MockContentSettingsObserver::Send(IPC::Message* message) { | 38 bool MockContentSettingsObserver::Send(IPC::Message* message) { |
| 39 IPC_BEGIN_MESSAGE_MAP(MockContentSettingsObserver, *message) | 39 IPC_BEGIN_MESSAGE_MAP(MockContentSettingsObserver, *message) |
| 40 IPC_MESSAGE_HANDLER(ViewHostMsg_ContentBlocked, OnContentBlocked) | 40 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked, OnContentBlocked) |
| 41 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_AllowDOMStorage, | 41 IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_AllowDOMStorage, |
| 42 OnAllowDOMStorage) | 42 OnAllowDOMStorage) |
| 43 IPC_MESSAGE_UNHANDLED(ADD_FAILURE()) | 43 IPC_MESSAGE_UNHANDLED(ADD_FAILURE()) |
| 44 IPC_END_MESSAGE_MAP() | 44 IPC_END_MESSAGE_MAP() |
| 45 | 45 |
| 46 // Our super class deletes the message. | 46 // Our super class deletes the message. |
| 47 return RenderViewObserver::Send(message); | 47 return RenderViewObserver::Send(message); |
| 48 } | 48 } |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 ProcessPendingMessages(); | 124 ProcessPendingMessages(); |
| 125 | 125 |
| 126 // 4. Verify that the notification that javascript was blocked is sent after | 126 // 4. Verify that the notification that javascript was blocked is sent after |
| 127 // the navigation notifiction is sent. | 127 // the navigation notifiction is sent. |
| 128 int navigation_index = -1; | 128 int navigation_index = -1; |
| 129 int block_index = -1; | 129 int block_index = -1; |
| 130 for (size_t i = 0; i < render_thread_.sink().message_count(); ++i) { | 130 for (size_t i = 0; i < render_thread_.sink().message_count(); ++i) { |
| 131 const IPC::Message* msg = render_thread_.sink().GetMessageAt(i); | 131 const IPC::Message* msg = render_thread_.sink().GetMessageAt(i); |
| 132 if (msg->type() == ViewHostMsg_FrameNavigate::ID) | 132 if (msg->type() == ViewHostMsg_FrameNavigate::ID) |
| 133 navigation_index = i; | 133 navigation_index = i; |
| 134 if (msg->type() == ViewHostMsg_ContentBlocked::ID) | 134 if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID) |
| 135 block_index = i; | 135 block_index = i; |
| 136 } | 136 } |
| 137 EXPECT_NE(-1, navigation_index); | 137 EXPECT_NE(-1, navigation_index); |
| 138 EXPECT_NE(-1, block_index); | 138 EXPECT_NE(-1, block_index); |
| 139 EXPECT_LT(navigation_index, block_index); | 139 EXPECT_LT(navigation_index, block_index); |
| 140 } | 140 } |
| 141 | 141 |
| 142 TEST_F(RenderViewTest, PluginsTemporarilyAllowed) { | 142 TEST_F(RenderViewTest, PluginsTemporarilyAllowed) { |
| 143 // Load some HTML. | 143 // Load some HTML. |
| 144 LoadHTML("<html>Foo</html>"); | 144 LoadHTML("<html>Foo</html>"); |
| 145 | 145 |
| 146 // Block plugins. | 146 // Block plugins. |
| 147 ContentSettings settings; | 147 ContentSettings settings; |
| 148 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) | 148 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) |
| 149 settings.settings[i] = CONTENT_SETTING_ALLOW; | 149 settings.settings[i] = CONTENT_SETTING_ALLOW; |
| 150 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS] = CONTENT_SETTING_BLOCK; | 150 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS] = CONTENT_SETTING_BLOCK; |
| 151 ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); | 151 ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); |
| 152 observer->SetContentSettings(settings); | 152 observer->SetContentSettings(settings); |
| 153 ContentSettingsObserver::SetDefaultContentSettings(settings); | 153 ContentSettingsObserver::SetDefaultContentSettings(settings); |
| 154 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 154 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 155 observer->GetContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS)); | 155 observer->GetContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 156 | 156 |
| 157 // Temporarily allow plugins. | 157 // Temporarily allow plugins. |
| 158 view_->OnMessageReceived(ViewMsg_LoadBlockedPlugins(MSG_ROUTING_NONE)); | 158 view_->OnMessageReceived(ChromeViewMsg_LoadBlockedPlugins(MSG_ROUTING_NONE)); |
| 159 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 159 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 160 observer->GetContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS)); | 160 observer->GetContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 161 | 161 |
| 162 // Simulate a navigation within the page. | 162 // Simulate a navigation within the page. |
| 163 view_->didNavigateWithinPage(GetMainFrame(), true); | 163 view_->didNavigateWithinPage(GetMainFrame(), true); |
| 164 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 164 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 165 observer->GetContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS)); | 165 observer->GetContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 166 | 166 |
| 167 // Navigate to a different page. | 167 // Navigate to a different page. |
| 168 LoadHTML("<html>Bar</html>"); | 168 LoadHTML("<html>Bar</html>"); |
| 169 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 169 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 170 observer->GetContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS)); | 170 observer->GetContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 171 } | 171 } |
| OLD | NEW |