| OLD | NEW |
| 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 "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" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/WebKit/public/web/WebView.h" | 13 #include "third_party/WebKit/public/web/WebView.h" |
| 14 | 14 |
| 15 using testing::_; | 15 using testing::_; |
| 16 using testing::DeleteArg; | 16 using testing::DeleteArg; |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 class MockContentSettingsObserver : public ContentSettingsObserver { | 20 class MockContentSettingsObserver : public ContentSettingsObserver { |
| 21 public: | 21 public: |
| 22 explicit MockContentSettingsObserver(content::RenderView* render_view); | 22 explicit MockContentSettingsObserver(content::RenderFrame* render_frame); |
| 23 | 23 |
| 24 virtual bool Send(IPC::Message* message); | 24 virtual bool Send(IPC::Message* message); |
| 25 | 25 |
| 26 MOCK_METHOD1(OnContentBlocked, | 26 MOCK_METHOD1(OnContentBlocked, |
| 27 void(ContentSettingsType)); | 27 void(ContentSettingsType)); |
| 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_; | 31 GURL image_url_; |
| 32 std::string image_origin_; | 32 std::string image_origin_; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 MockContentSettingsObserver::MockContentSettingsObserver( | 35 MockContentSettingsObserver::MockContentSettingsObserver( |
| 36 content::RenderView* render_view) | 36 content::RenderFrame* render_frame) |
| 37 : ContentSettingsObserver(render_view, NULL), | 37 : ContentSettingsObserver(render_frame, NULL), |
| 38 image_url_("http://www.foo.com/image.jpg"), | 38 image_url_("http://www.foo.com/image.jpg"), |
| 39 image_origin_("http://www.foo.com") { | 39 image_origin_("http://www.foo.com") { |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool MockContentSettingsObserver::Send(IPC::Message* message) { | 42 bool MockContentSettingsObserver::Send(IPC::Message* message) { |
| 43 IPC_BEGIN_MESSAGE_MAP(MockContentSettingsObserver, *message) | 43 IPC_BEGIN_MESSAGE_MAP(MockContentSettingsObserver, *message) |
| 44 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked, OnContentBlocked) | 44 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked, OnContentBlocked) |
| 45 IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_AllowDOMStorage, | 45 IPC_MESSAGE_HANDLER_DELAY_REPLY(ChromeViewHostMsg_AllowDOMStorage, |
| 46 OnAllowDOMStorage) | 46 OnAllowDOMStorage) |
| 47 IPC_MESSAGE_UNHANDLED(ADD_FAILURE()) | 47 IPC_MESSAGE_UNHANDLED(ADD_FAILURE()) |
| 48 IPC_END_MESSAGE_MAP() | 48 IPC_END_MESSAGE_MAP() |
| 49 | 49 |
| 50 // Our super class deletes the message. | 50 // Our super class deletes the message. |
| 51 return RenderViewObserver::Send(message); | 51 return RenderFrameObserver::Send(message); |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 TEST_F(ChromeRenderViewTest, DidBlockContentType) { | 56 TEST_F(ChromeRenderViewTest, DidBlockContentType) { |
| 57 MockContentSettingsObserver observer(view_); | 57 MockContentSettingsObserver observer(view_->GetMainRenderFrame()); |
| 58 EXPECT_CALL(observer, | 58 EXPECT_CALL(observer, |
| 59 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); | 59 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 60 observer.DidBlockContentType(CONTENT_SETTINGS_TYPE_COOKIES); | 60 observer.DidBlockContentType(CONTENT_SETTINGS_TYPE_COOKIES); |
| 61 | 61 |
| 62 // Blocking the same content type a second time shouldn't send a notification. | 62 // Blocking the same content type a second time shouldn't send a notification. |
| 63 observer.DidBlockContentType(CONTENT_SETTINGS_TYPE_COOKIES); | 63 observer.DidBlockContentType(CONTENT_SETTINGS_TYPE_COOKIES); |
| 64 ::testing::Mock::VerifyAndClearExpectations(&observer); | 64 ::testing::Mock::VerifyAndClearExpectations(&observer); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Tests that multiple invokations of AllowDOMStorage result in a single IPC. | 67 // Tests that multiple invokations of AllowDOMStorage result in a single IPC. |
| 68 // Fails due to http://crbug.com/104300 | 68 // Fails due to http://crbug.com/104300 |
| 69 TEST_F(ChromeRenderViewTest, DISABLED_AllowDOMStorage) { | 69 TEST_F(ChromeRenderViewTest, DISABLED_AllowDOMStorage) { |
| 70 // Load some HTML, so we have a valid security origin. | 70 // Load some HTML, so we have a valid security origin. |
| 71 LoadHTML("<html></html>"); | 71 LoadHTML("<html></html>"); |
| 72 MockContentSettingsObserver observer(view_); | 72 MockContentSettingsObserver observer(view_->GetMainRenderFrame()); |
| 73 ON_CALL(observer, | 73 ON_CALL(observer, |
| 74 OnAllowDOMStorage(_, _, _, _, _)).WillByDefault(DeleteArg<4>()); | 74 OnAllowDOMStorage(_, _, _, _, _)).WillByDefault(DeleteArg<4>()); |
| 75 EXPECT_CALL(observer, | 75 EXPECT_CALL(observer, |
| 76 OnAllowDOMStorage(_, _, _, _, _)); | 76 OnAllowDOMStorage(_, _, _, _, _)); |
| 77 observer.allowStorage(view_->GetWebView()->focusedFrame(), true); | 77 observer.allowStorage(view_->GetWebView()->focusedFrame(), true); |
| 78 | 78 |
| 79 // Accessing localStorage from the same origin again shouldn't result in a | 79 // Accessing localStorage from the same origin again shouldn't result in a |
| 80 // new IPC. | 80 // new IPC. |
| 81 observer.allowStorage(view_->GetWebView()->focusedFrame(), true); | 81 observer.allowStorage(view_->GetWebView()->focusedFrame(), true); |
| 82 ::testing::Mock::VerifyAndClearExpectations(&observer); | 82 ::testing::Mock::VerifyAndClearExpectations(&observer); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 98 // 2. Block JavaScript. | 98 // 2. Block JavaScript. |
| 99 RendererContentSettingRules content_setting_rules; | 99 RendererContentSettingRules content_setting_rules; |
| 100 ContentSettingsForOneType& script_setting_rules = | 100 ContentSettingsForOneType& script_setting_rules = |
| 101 content_setting_rules.script_rules; | 101 content_setting_rules.script_rules; |
| 102 script_setting_rules.push_back( | 102 script_setting_rules.push_back( |
| 103 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 103 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), |
| 104 ContentSettingsPattern::Wildcard(), | 104 ContentSettingsPattern::Wildcard(), |
| 105 CONTENT_SETTING_BLOCK, | 105 CONTENT_SETTING_BLOCK, |
| 106 std::string(), | 106 std::string(), |
| 107 false)); | 107 false)); |
| 108 ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); | 108 ContentSettingsObserver* observer = ContentSettingsObserver::Get( |
| 109 view_->GetMainRenderFrame()); |
| 109 observer->SetContentSettingRules(&content_setting_rules); | 110 observer->SetContentSettingRules(&content_setting_rules); |
| 110 | 111 |
| 111 // Make sure no pending messages are in the queue. | 112 // Make sure no pending messages are in the queue. |
| 112 ProcessPendingMessages(); | 113 ProcessPendingMessages(); |
| 113 render_thread_->sink().ClearMessages(); | 114 render_thread_->sink().ClearMessages(); |
| 114 | 115 |
| 115 // 3. Reload page. | 116 // 3. Reload page. |
| 116 std::string url_str = "data:text/html;charset=utf-8,"; | 117 std::string url_str = "data:text/html;charset=utf-8,"; |
| 117 url_str.append(html); | 118 url_str.append(html); |
| 118 GURL url(url_str); | 119 GURL url(url_str); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 135 EXPECT_LT(navigation_index, block_index); | 136 EXPECT_LT(navigation_index, block_index); |
| 136 } | 137 } |
| 137 | 138 |
| 138 TEST_F(ChromeRenderViewTest, PluginsTemporarilyAllowed) { | 139 TEST_F(ChromeRenderViewTest, PluginsTemporarilyAllowed) { |
| 139 // Load some HTML. | 140 // Load some HTML. |
| 140 LoadHTML("<html>Foo</html>"); | 141 LoadHTML("<html>Foo</html>"); |
| 141 | 142 |
| 142 std::string foo_plugin = "foo"; | 143 std::string foo_plugin = "foo"; |
| 143 std::string bar_plugin = "bar"; | 144 std::string bar_plugin = "bar"; |
| 144 | 145 |
| 145 ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); | 146 ContentSettingsObserver* observer = |
| 147 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); |
| 146 EXPECT_FALSE(observer->IsPluginTemporarilyAllowed(foo_plugin)); | 148 EXPECT_FALSE(observer->IsPluginTemporarilyAllowed(foo_plugin)); |
| 147 | 149 |
| 148 // Temporarily allow the "foo" plugin. | 150 // Temporarily allow the "foo" plugin. |
| 149 OnMessageReceived(ChromeViewMsg_LoadBlockedPlugins(MSG_ROUTING_NONE, | 151 observer->OnLoadBlockedPlugins(foo_plugin); |
| 150 foo_plugin)); | |
| 151 EXPECT_TRUE(observer->IsPluginTemporarilyAllowed(foo_plugin)); | 152 EXPECT_TRUE(observer->IsPluginTemporarilyAllowed(foo_plugin)); |
| 152 EXPECT_FALSE(observer->IsPluginTemporarilyAllowed(bar_plugin)); | 153 EXPECT_FALSE(observer->IsPluginTemporarilyAllowed(bar_plugin)); |
| 153 | 154 |
| 154 // Simulate a navigation within the page. | 155 // Simulate a navigation within the page. |
| 155 DidNavigateWithinPage(GetMainFrame(), true); | 156 DidNavigateWithinPage(GetMainFrame(), true); |
| 156 EXPECT_TRUE(observer->IsPluginTemporarilyAllowed(foo_plugin)); | 157 EXPECT_TRUE(observer->IsPluginTemporarilyAllowed(foo_plugin)); |
| 157 EXPECT_FALSE(observer->IsPluginTemporarilyAllowed(bar_plugin)); | 158 EXPECT_FALSE(observer->IsPluginTemporarilyAllowed(bar_plugin)); |
| 158 | 159 |
| 159 // Navigate to a different page. | 160 // Navigate to a different page. |
| 160 LoadHTML("<html>Bar</html>"); | 161 LoadHTML("<html>Bar</html>"); |
| 161 EXPECT_FALSE(observer->IsPluginTemporarilyAllowed(foo_plugin)); | 162 EXPECT_FALSE(observer->IsPluginTemporarilyAllowed(foo_plugin)); |
| 162 EXPECT_FALSE(observer->IsPluginTemporarilyAllowed(bar_plugin)); | 163 EXPECT_FALSE(observer->IsPluginTemporarilyAllowed(bar_plugin)); |
| 163 | 164 |
| 164 // Temporarily allow all plugins. | 165 // Temporarily allow all plugins. |
| 165 OnMessageReceived(ChromeViewMsg_LoadBlockedPlugins(MSG_ROUTING_NONE, | 166 observer->OnLoadBlockedPlugins(std::string()); |
| 166 std::string())); | |
| 167 EXPECT_TRUE(observer->IsPluginTemporarilyAllowed(foo_plugin)); | 167 EXPECT_TRUE(observer->IsPluginTemporarilyAllowed(foo_plugin)); |
| 168 EXPECT_TRUE(observer->IsPluginTemporarilyAllowed(bar_plugin)); | 168 EXPECT_TRUE(observer->IsPluginTemporarilyAllowed(bar_plugin)); |
| 169 } | 169 } |
| 170 | 170 |
| 171 TEST_F(ChromeRenderViewTest, ImagesBlockedByDefault) { | 171 TEST_F(ChromeRenderViewTest, ImagesBlockedByDefault) { |
| 172 MockContentSettingsObserver mock_observer(view_); | 172 MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame()); |
| 173 | 173 |
| 174 // Load some HTML. | 174 // Load some HTML. |
| 175 LoadHTML("<html>Foo</html>"); | 175 LoadHTML("<html>Foo</html>"); |
| 176 | 176 |
| 177 // Set the default image blocking setting. | 177 // Set the default image blocking setting. |
| 178 RendererContentSettingRules content_setting_rules; | 178 RendererContentSettingRules content_setting_rules; |
| 179 ContentSettingsForOneType& image_setting_rules = | 179 ContentSettingsForOneType& image_setting_rules = |
| 180 content_setting_rules.image_rules; | 180 content_setting_rules.image_rules; |
| 181 image_setting_rules.push_back( | 181 image_setting_rules.push_back( |
| 182 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 182 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), |
| 183 ContentSettingsPattern::Wildcard(), | 183 ContentSettingsPattern::Wildcard(), |
| 184 CONTENT_SETTING_BLOCK, | 184 CONTENT_SETTING_BLOCK, |
| 185 std::string(), | 185 std::string(), |
| 186 false)); | 186 false)); |
| 187 | 187 |
| 188 ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); | 188 ContentSettingsObserver* observer = ContentSettingsObserver::Get( |
| 189 view_->GetMainRenderFrame()); |
| 189 observer->SetContentSettingRules(&content_setting_rules); | 190 observer->SetContentSettingRules(&content_setting_rules); |
| 190 EXPECT_CALL(mock_observer, | 191 EXPECT_CALL(mock_observer, |
| 191 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)); | 192 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)); |
| 192 EXPECT_FALSE(observer->allowImage(GetMainFrame(), | 193 EXPECT_FALSE(observer->allowImage(GetMainFrame(), |
| 193 true, mock_observer.image_url_)); | 194 true, mock_observer.image_url_)); |
| 194 ::testing::Mock::VerifyAndClearExpectations(&observer); | 195 ::testing::Mock::VerifyAndClearExpectations(&observer); |
| 195 | 196 |
| 196 // Create an exception which allows the image. | 197 // Create an exception which allows the image. |
| 197 image_setting_rules.insert( | 198 image_setting_rules.insert( |
| 198 image_setting_rules.begin(), | 199 image_setting_rules.begin(), |
| 199 ContentSettingPatternSource( | 200 ContentSettingPatternSource( |
| 200 ContentSettingsPattern::Wildcard(), | 201 ContentSettingsPattern::Wildcard(), |
| 201 ContentSettingsPattern::FromString(mock_observer.image_origin_), | 202 ContentSettingsPattern::FromString(mock_observer.image_origin_), |
| 202 CONTENT_SETTING_ALLOW, | 203 CONTENT_SETTING_ALLOW, |
| 203 std::string(), | 204 std::string(), |
| 204 false)); | 205 false)); |
| 205 | 206 |
| 206 EXPECT_CALL( | 207 EXPECT_CALL( |
| 207 mock_observer, | 208 mock_observer, |
| 208 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); | 209 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); |
| 209 EXPECT_TRUE(observer->allowImage(GetMainFrame(), true, | 210 EXPECT_TRUE(observer->allowImage(GetMainFrame(), true, |
| 210 mock_observer.image_url_)); | 211 mock_observer.image_url_)); |
| 211 ::testing::Mock::VerifyAndClearExpectations(&observer); | 212 ::testing::Mock::VerifyAndClearExpectations(&observer); |
| 212 } | 213 } |
| 213 | 214 |
| 214 TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) { | 215 TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) { |
| 215 MockContentSettingsObserver mock_observer(view_); | 216 MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame()); |
| 216 | 217 |
| 217 // Load some HTML. | 218 // Load some HTML. |
| 218 LoadHTML("<html>Foo</html>"); | 219 LoadHTML("<html>Foo</html>"); |
| 219 | 220 |
| 220 // Set the default image blocking setting. | 221 // Set the default image blocking setting. |
| 221 RendererContentSettingRules content_setting_rules; | 222 RendererContentSettingRules content_setting_rules; |
| 222 ContentSettingsForOneType& image_setting_rules = | 223 ContentSettingsForOneType& image_setting_rules = |
| 223 content_setting_rules.image_rules; | 224 content_setting_rules.image_rules; |
| 224 image_setting_rules.push_back( | 225 image_setting_rules.push_back( |
| 225 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 226 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), |
| 226 ContentSettingsPattern::Wildcard(), | 227 ContentSettingsPattern::Wildcard(), |
| 227 CONTENT_SETTING_ALLOW, | 228 CONTENT_SETTING_ALLOW, |
| 228 std::string(), | 229 std::string(), |
| 229 false)); | 230 false)); |
| 230 | 231 |
| 231 ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); | 232 ContentSettingsObserver* observer = |
| 233 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); |
| 232 observer->SetContentSettingRules(&content_setting_rules); | 234 observer->SetContentSettingRules(&content_setting_rules); |
| 233 EXPECT_CALL( | 235 EXPECT_CALL( |
| 234 mock_observer, | 236 mock_observer, |
| 235 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); | 237 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); |
| 236 EXPECT_TRUE(observer->allowImage(GetMainFrame(), true, | 238 EXPECT_TRUE(observer->allowImage(GetMainFrame(), true, |
| 237 mock_observer.image_url_)); | 239 mock_observer.image_url_)); |
| 238 ::testing::Mock::VerifyAndClearExpectations(&observer); | 240 ::testing::Mock::VerifyAndClearExpectations(&observer); |
| 239 | 241 |
| 240 // Create an exception which blocks the image. | 242 // Create an exception which blocks the image. |
| 241 image_setting_rules.insert( | 243 image_setting_rules.insert( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 258 RendererContentSettingRules content_setting_rules; | 260 RendererContentSettingRules content_setting_rules; |
| 259 ContentSettingsForOneType& script_setting_rules = | 261 ContentSettingsForOneType& script_setting_rules = |
| 260 content_setting_rules.script_rules; | 262 content_setting_rules.script_rules; |
| 261 script_setting_rules.push_back( | 263 script_setting_rules.push_back( |
| 262 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 264 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), |
| 263 ContentSettingsPattern::Wildcard(), | 265 ContentSettingsPattern::Wildcard(), |
| 264 CONTENT_SETTING_BLOCK, | 266 CONTENT_SETTING_BLOCK, |
| 265 std::string(), | 267 std::string(), |
| 266 false)); | 268 false)); |
| 267 | 269 |
| 268 ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); | 270 ContentSettingsObserver* observer = |
| 271 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); |
| 269 observer->SetContentSettingRules(&content_setting_rules); | 272 observer->SetContentSettingRules(&content_setting_rules); |
| 270 | 273 |
| 271 // Load a page which contains a script. | 274 // Load a page which contains a script. |
| 272 std::string html = "<html>" | 275 std::string html = "<html>" |
| 273 "<head>" | 276 "<head>" |
| 274 "<script src='data:foo'></script>" | 277 "<script src='data:foo'></script>" |
| 275 "</head>" | 278 "</head>" |
| 276 "<body>" | 279 "<body>" |
| 277 "</body>" | 280 "</body>" |
| 278 "</html>"; | 281 "</html>"; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 293 RendererContentSettingRules content_setting_rules; | 296 RendererContentSettingRules content_setting_rules; |
| 294 ContentSettingsForOneType& script_setting_rules = | 297 ContentSettingsForOneType& script_setting_rules = |
| 295 content_setting_rules.script_rules; | 298 content_setting_rules.script_rules; |
| 296 script_setting_rules.push_back( | 299 script_setting_rules.push_back( |
| 297 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 300 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), |
| 298 ContentSettingsPattern::Wildcard(), | 301 ContentSettingsPattern::Wildcard(), |
| 299 CONTENT_SETTING_ALLOW, | 302 CONTENT_SETTING_ALLOW, |
| 300 std::string(), | 303 std::string(), |
| 301 false)); | 304 false)); |
| 302 | 305 |
| 303 ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); | 306 ContentSettingsObserver* observer = |
| 307 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); |
| 304 observer->SetContentSettingRules(&content_setting_rules); | 308 observer->SetContentSettingRules(&content_setting_rules); |
| 305 | 309 |
| 306 // Load a page which contains a script. | 310 // Load a page which contains a script. |
| 307 std::string html = "<html>" | 311 std::string html = "<html>" |
| 308 "<head>" | 312 "<head>" |
| 309 "<script src='data:foo'></script>" | 313 "<script src='data:foo'></script>" |
| 310 "</head>" | 314 "</head>" |
| 311 "<body>" | 315 "<body>" |
| 312 "</body>" | 316 "</body>" |
| 313 "</html>"; | 317 "</html>"; |
| 314 LoadHTML(html.c_str()); | 318 LoadHTML(html.c_str()); |
| 315 | 319 |
| 316 // Verify that the script was not blocked. | 320 // Verify that the script was not blocked. |
| 317 bool was_blocked = false; | 321 bool was_blocked = false; |
| 318 for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) { | 322 for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) { |
| 319 const IPC::Message* msg = render_thread_->sink().GetMessageAt(i); | 323 const IPC::Message* msg = render_thread_->sink().GetMessageAt(i); |
| 320 if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID) | 324 if (msg->type() == ChromeViewHostMsg_ContentBlocked::ID) |
| 321 was_blocked = true; | 325 was_blocked = true; |
| 322 } | 326 } |
| 323 EXPECT_FALSE(was_blocked); | 327 EXPECT_FALSE(was_blocked); |
| 324 } | 328 } |
| 325 | 329 |
| 326 TEST_F(ChromeRenderViewTest, ContentSettingsInterstitialPages) { | 330 TEST_F(ChromeRenderViewTest, ContentSettingsInterstitialPages) { |
| 327 MockContentSettingsObserver mock_observer(view_); | 331 MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame()); |
| 328 // Block scripts. | 332 // Block scripts. |
| 329 RendererContentSettingRules content_setting_rules; | 333 RendererContentSettingRules content_setting_rules; |
| 330 ContentSettingsForOneType& script_setting_rules = | 334 ContentSettingsForOneType& script_setting_rules = |
| 331 content_setting_rules.script_rules; | 335 content_setting_rules.script_rules; |
| 332 script_setting_rules.push_back( | 336 script_setting_rules.push_back( |
| 333 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 337 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), |
| 334 ContentSettingsPattern::Wildcard(), | 338 ContentSettingsPattern::Wildcard(), |
| 335 CONTENT_SETTING_BLOCK, | 339 CONTENT_SETTING_BLOCK, |
| 336 std::string(), | 340 std::string(), |
| 337 false)); | 341 false)); |
| 338 // Block images. | 342 // Block images. |
| 339 ContentSettingsForOneType& image_setting_rules = | 343 ContentSettingsForOneType& image_setting_rules = |
| 340 content_setting_rules.image_rules; | 344 content_setting_rules.image_rules; |
| 341 image_setting_rules.push_back( | 345 image_setting_rules.push_back( |
| 342 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 346 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), |
| 343 ContentSettingsPattern::Wildcard(), | 347 ContentSettingsPattern::Wildcard(), |
| 344 CONTENT_SETTING_BLOCK, | 348 CONTENT_SETTING_BLOCK, |
| 345 std::string(), | 349 std::string(), |
| 346 false)); | 350 false)); |
| 347 | 351 |
| 348 ContentSettingsObserver* observer = ContentSettingsObserver::Get(view_); | 352 ContentSettingsObserver* observer = |
| 353 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); |
| 349 observer->SetContentSettingRules(&content_setting_rules); | 354 observer->SetContentSettingRules(&content_setting_rules); |
| 350 observer->OnSetAsInterstitial(); | 355 observer->OnSetAsInterstitial(); |
| 351 | 356 |
| 352 // Load a page which contains a script. | 357 // Load a page which contains a script. |
| 353 std::string html = "<html>" | 358 std::string html = "<html>" |
| 354 "<head>" | 359 "<head>" |
| 355 "<script src='data:foo'></script>" | 360 "<script src='data:foo'></script>" |
| 356 "</head>" | 361 "</head>" |
| 357 "<body>" | 362 "<body>" |
| 358 "</body>" | 363 "</body>" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 369 EXPECT_FALSE(was_blocked); | 374 EXPECT_FALSE(was_blocked); |
| 370 | 375 |
| 371 // Verify that images are allowed. | 376 // Verify that images are allowed. |
| 372 EXPECT_CALL( | 377 EXPECT_CALL( |
| 373 mock_observer, | 378 mock_observer, |
| 374 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); | 379 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES)).Times(0); |
| 375 EXPECT_TRUE(observer->allowImage(GetMainFrame(), true, | 380 EXPECT_TRUE(observer->allowImage(GetMainFrame(), true, |
| 376 mock_observer.image_url_)); | 381 mock_observer.image_url_)); |
| 377 ::testing::Mock::VerifyAndClearExpectations(&observer); | 382 ::testing::Mock::VerifyAndClearExpectations(&observer); |
| 378 } | 383 } |
| OLD | NEW |