| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/values.h" |
| 8 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
| 9 #include "chrome/renderer/content_settings_observer.h" | 10 #include "chrome/renderer/content_settings_observer.h" |
| 10 #include "chrome/test/base/chrome_render_view_test.h" | 11 #include "chrome/test/base/chrome_render_view_test.h" |
| 11 #include "components/content_settings/core/common/content_settings.h" | 12 #include "components/content_settings/core/common/content_settings.h" |
| 13 #include "components/content_settings/core/common/content_settings_utils.h" |
| 12 #include "content/public/renderer/render_view.h" | 14 #include "content/public/renderer/render_view.h" |
| 13 #include "ipc/ipc_message_macros.h" | 15 #include "ipc/ipc_message_macros.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" | 18 #include "third_party/WebKit/public/web/WebFrameContentDumper.h" |
| 17 #include "third_party/WebKit/public/web/WebView.h" | 19 #include "third_party/WebKit/public/web/WebView.h" |
| 18 | 20 |
| 19 using testing::_; | 21 using testing::_; |
| 20 using testing::DeleteArg; | 22 using testing::DeleteArg; |
| 21 | 23 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 "<body>" | 99 "<body>" |
| 98 "</body>" | 100 "</body>" |
| 99 "</html>"; | 101 "</html>"; |
| 100 render_thread_->sink().ClearMessages(); | 102 render_thread_->sink().ClearMessages(); |
| 101 LoadHTML(kHtml); | 103 LoadHTML(kHtml); |
| 102 | 104 |
| 103 // 2. Block JavaScript. | 105 // 2. Block JavaScript. |
| 104 RendererContentSettingRules content_setting_rules; | 106 RendererContentSettingRules content_setting_rules; |
| 105 ContentSettingsForOneType& script_setting_rules = | 107 ContentSettingsForOneType& script_setting_rules = |
| 106 content_setting_rules.script_rules; | 108 content_setting_rules.script_rules; |
| 107 script_setting_rules.push_back( | 109 script_setting_rules.push_back(ContentSettingPatternSource( |
| 108 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 110 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), |
| 109 ContentSettingsPattern::Wildcard(), | 111 content_settings::ContentSettingToValue(CONTENT_SETTING_BLOCK), |
| 110 CONTENT_SETTING_BLOCK, | 112 std::string(), false)); |
| 111 std::string(), | |
| 112 false)); | |
| 113 ContentSettingsObserver* observer = ContentSettingsObserver::Get( | 113 ContentSettingsObserver* observer = ContentSettingsObserver::Get( |
| 114 view_->GetMainRenderFrame()); | 114 view_->GetMainRenderFrame()); |
| 115 observer->SetContentSettingRules(&content_setting_rules); | 115 observer->SetContentSettingRules(&content_setting_rules); |
| 116 | 116 |
| 117 // Make sure no pending messages are in the queue. | 117 // Make sure no pending messages are in the queue. |
| 118 base::RunLoop().RunUntilIdle(); | 118 base::RunLoop().RunUntilIdle(); |
| 119 render_thread_->sink().ClearMessages(); | 119 render_thread_->sink().ClearMessages(); |
| 120 | 120 |
| 121 // 3. Reload page. | 121 // 3. Reload page. |
| 122 std::string url_str = "data:text/html;charset=utf-8,"; | 122 std::string url_str = "data:text/html;charset=utf-8,"; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 TEST_F(ChromeRenderViewTest, ImagesBlockedByDefault) { | 176 TEST_F(ChromeRenderViewTest, ImagesBlockedByDefault) { |
| 177 MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame()); | 177 MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame()); |
| 178 | 178 |
| 179 // Load some HTML. | 179 // Load some HTML. |
| 180 LoadHTML("<html>Foo</html>"); | 180 LoadHTML("<html>Foo</html>"); |
| 181 | 181 |
| 182 // Set the default image blocking setting. | 182 // Set the default image blocking setting. |
| 183 RendererContentSettingRules content_setting_rules; | 183 RendererContentSettingRules content_setting_rules; |
| 184 ContentSettingsForOneType& image_setting_rules = | 184 ContentSettingsForOneType& image_setting_rules = |
| 185 content_setting_rules.image_rules; | 185 content_setting_rules.image_rules; |
| 186 image_setting_rules.push_back( | 186 image_setting_rules.push_back(ContentSettingPatternSource( |
| 187 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 187 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), |
| 188 ContentSettingsPattern::Wildcard(), | 188 content_settings::ContentSettingToValue(CONTENT_SETTING_BLOCK), |
| 189 CONTENT_SETTING_BLOCK, | 189 std::string(), false)); |
| 190 std::string(), | |
| 191 false)); | |
| 192 | 190 |
| 193 ContentSettingsObserver* observer = ContentSettingsObserver::Get( | 191 ContentSettingsObserver* observer = ContentSettingsObserver::Get( |
| 194 view_->GetMainRenderFrame()); | 192 view_->GetMainRenderFrame()); |
| 195 observer->SetContentSettingRules(&content_setting_rules); | 193 observer->SetContentSettingRules(&content_setting_rules); |
| 196 EXPECT_CALL(mock_observer, | 194 EXPECT_CALL(mock_observer, |
| 197 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, base::string16())); | 195 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, base::string16())); |
| 198 EXPECT_FALSE(observer->AllowImage(true, mock_observer.image_url_)); | 196 EXPECT_FALSE(observer->AllowImage(true, mock_observer.image_url_)); |
| 199 ::testing::Mock::VerifyAndClearExpectations(&observer); | 197 ::testing::Mock::VerifyAndClearExpectations(&observer); |
| 200 | 198 |
| 201 // Create an exception which allows the image. | 199 // Create an exception which allows the image. |
| 202 image_setting_rules.insert( | 200 image_setting_rules.insert( |
| 203 image_setting_rules.begin(), | 201 image_setting_rules.begin(), |
| 204 ContentSettingPatternSource( | 202 ContentSettingPatternSource( |
| 205 ContentSettingsPattern::Wildcard(), | 203 ContentSettingsPattern::Wildcard(), |
| 206 ContentSettingsPattern::FromString(mock_observer.image_origin_), | 204 ContentSettingsPattern::FromString(mock_observer.image_origin_), |
| 207 CONTENT_SETTING_ALLOW, | 205 content_settings::ContentSettingToValue(CONTENT_SETTING_ALLOW), |
| 208 std::string(), | 206 std::string(), false)); |
| 209 false)); | |
| 210 | 207 |
| 211 EXPECT_CALL(mock_observer, OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, | 208 EXPECT_CALL(mock_observer, OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, |
| 212 base::string16())).Times(0); | 209 base::string16())).Times(0); |
| 213 EXPECT_TRUE(observer->AllowImage(true, mock_observer.image_url_)); | 210 EXPECT_TRUE(observer->AllowImage(true, mock_observer.image_url_)); |
| 214 ::testing::Mock::VerifyAndClearExpectations(&observer); | 211 ::testing::Mock::VerifyAndClearExpectations(&observer); |
| 215 } | 212 } |
| 216 | 213 |
| 217 TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) { | 214 TEST_F(ChromeRenderViewTest, ImagesAllowedByDefault) { |
| 218 MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame()); | 215 MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame()); |
| 219 | 216 |
| 220 // Load some HTML. | 217 // Load some HTML. |
| 221 LoadHTML("<html>Foo</html>"); | 218 LoadHTML("<html>Foo</html>"); |
| 222 | 219 |
| 223 // Set the default image blocking setting. | 220 // Set the default image blocking setting. |
| 224 RendererContentSettingRules content_setting_rules; | 221 RendererContentSettingRules content_setting_rules; |
| 225 ContentSettingsForOneType& image_setting_rules = | 222 ContentSettingsForOneType& image_setting_rules = |
| 226 content_setting_rules.image_rules; | 223 content_setting_rules.image_rules; |
| 227 image_setting_rules.push_back( | 224 image_setting_rules.push_back(ContentSettingPatternSource( |
| 228 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 225 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), |
| 229 ContentSettingsPattern::Wildcard(), | 226 content_settings::ContentSettingToValue(CONTENT_SETTING_ALLOW), |
| 230 CONTENT_SETTING_ALLOW, | 227 std::string(), false)); |
| 231 std::string(), | |
| 232 false)); | |
| 233 | 228 |
| 234 ContentSettingsObserver* observer = | 229 ContentSettingsObserver* observer = |
| 235 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); | 230 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); |
| 236 observer->SetContentSettingRules(&content_setting_rules); | 231 observer->SetContentSettingRules(&content_setting_rules); |
| 237 EXPECT_CALL(mock_observer, OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, | 232 EXPECT_CALL(mock_observer, OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, |
| 238 base::string16())).Times(0); | 233 base::string16())).Times(0); |
| 239 EXPECT_TRUE(observer->AllowImage(true, mock_observer.image_url_)); | 234 EXPECT_TRUE(observer->AllowImage(true, mock_observer.image_url_)); |
| 240 ::testing::Mock::VerifyAndClearExpectations(&observer); | 235 ::testing::Mock::VerifyAndClearExpectations(&observer); |
| 241 | 236 |
| 242 // Create an exception which blocks the image. | 237 // Create an exception which blocks the image. |
| 243 image_setting_rules.insert( | 238 image_setting_rules.insert( |
| 244 image_setting_rules.begin(), | 239 image_setting_rules.begin(), |
| 245 ContentSettingPatternSource( | 240 ContentSettingPatternSource( |
| 246 ContentSettingsPattern::Wildcard(), | 241 ContentSettingsPattern::Wildcard(), |
| 247 ContentSettingsPattern::FromString(mock_observer.image_origin_), | 242 ContentSettingsPattern::FromString(mock_observer.image_origin_), |
| 248 CONTENT_SETTING_BLOCK, | 243 content_settings::ContentSettingToValue(CONTENT_SETTING_BLOCK), |
| 249 std::string(), | 244 std::string(), false)); |
| 250 false)); | |
| 251 EXPECT_CALL(mock_observer, | 245 EXPECT_CALL(mock_observer, |
| 252 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, base::string16())); | 246 OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, base::string16())); |
| 253 EXPECT_FALSE(observer->AllowImage(true, mock_observer.image_url_)); | 247 EXPECT_FALSE(observer->AllowImage(true, mock_observer.image_url_)); |
| 254 ::testing::Mock::VerifyAndClearExpectations(&observer); | 248 ::testing::Mock::VerifyAndClearExpectations(&observer); |
| 255 } | 249 } |
| 256 | 250 |
| 257 TEST_F(ChromeRenderViewTest, ContentSettingsBlockScripts) { | 251 TEST_F(ChromeRenderViewTest, ContentSettingsBlockScripts) { |
| 258 // Set the content settings for scripts. | 252 // Set the content settings for scripts. |
| 259 RendererContentSettingRules content_setting_rules; | 253 RendererContentSettingRules content_setting_rules; |
| 260 ContentSettingsForOneType& script_setting_rules = | 254 ContentSettingsForOneType& script_setting_rules = |
| 261 content_setting_rules.script_rules; | 255 content_setting_rules.script_rules; |
| 262 script_setting_rules.push_back( | 256 script_setting_rules.push_back(ContentSettingPatternSource( |
| 263 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 257 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), |
| 264 ContentSettingsPattern::Wildcard(), | 258 content_settings::ContentSettingToValue(CONTENT_SETTING_BLOCK), |
| 265 CONTENT_SETTING_BLOCK, | 259 std::string(), false)); |
| 266 std::string(), | |
| 267 false)); | |
| 268 | 260 |
| 269 ContentSettingsObserver* observer = | 261 ContentSettingsObserver* observer = |
| 270 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); | 262 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); |
| 271 observer->SetContentSettingRules(&content_setting_rules); | 263 observer->SetContentSettingRules(&content_setting_rules); |
| 272 | 264 |
| 273 // Load a page which contains a script. | 265 // Load a page which contains a script. |
| 274 const char kHtml[] = | 266 const char kHtml[] = |
| 275 "<html>" | 267 "<html>" |
| 276 "<head>" | 268 "<head>" |
| 277 "<script src='data:foo'></script>" | 269 "<script src='data:foo'></script>" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 289 was_blocked = true; | 281 was_blocked = true; |
| 290 } | 282 } |
| 291 EXPECT_TRUE(was_blocked); | 283 EXPECT_TRUE(was_blocked); |
| 292 } | 284 } |
| 293 | 285 |
| 294 TEST_F(ChromeRenderViewTest, ContentSettingsAllowScripts) { | 286 TEST_F(ChromeRenderViewTest, ContentSettingsAllowScripts) { |
| 295 // Set the content settings for scripts. | 287 // Set the content settings for scripts. |
| 296 RendererContentSettingRules content_setting_rules; | 288 RendererContentSettingRules content_setting_rules; |
| 297 ContentSettingsForOneType& script_setting_rules = | 289 ContentSettingsForOneType& script_setting_rules = |
| 298 content_setting_rules.script_rules; | 290 content_setting_rules.script_rules; |
| 299 script_setting_rules.push_back( | 291 script_setting_rules.push_back(ContentSettingPatternSource( |
| 300 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 292 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), |
| 301 ContentSettingsPattern::Wildcard(), | 293 content_settings::ContentSettingToValue(CONTENT_SETTING_ALLOW), |
| 302 CONTENT_SETTING_ALLOW, | 294 std::string(), false)); |
| 303 std::string(), | |
| 304 false)); | |
| 305 | 295 |
| 306 ContentSettingsObserver* observer = | 296 ContentSettingsObserver* observer = |
| 307 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); | 297 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); |
| 308 observer->SetContentSettingRules(&content_setting_rules); | 298 observer->SetContentSettingRules(&content_setting_rules); |
| 309 | 299 |
| 310 // Load a page which contains a script. | 300 // Load a page which contains a script. |
| 311 const char kHtml[] = | 301 const char kHtml[] = |
| 312 "<html>" | 302 "<html>" |
| 313 "<head>" | 303 "<head>" |
| 314 "<script src='data:foo'></script>" | 304 "<script src='data:foo'></script>" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 331 // Regression test for crbug.com/232410: Load a page with JS blocked. Then, | 321 // Regression test for crbug.com/232410: Load a page with JS blocked. Then, |
| 332 // allow JS and reload the page. In each case, only one of noscript or script | 322 // allow JS and reload the page. In each case, only one of noscript or script |
| 333 // tags should be enabled, but never both. | 323 // tags should be enabled, but never both. |
| 334 TEST_F(ChromeRenderViewTest, ContentSettingsNoscriptTag) { | 324 TEST_F(ChromeRenderViewTest, ContentSettingsNoscriptTag) { |
| 335 // 1. Block JavaScript. | 325 // 1. Block JavaScript. |
| 336 RendererContentSettingRules content_setting_rules; | 326 RendererContentSettingRules content_setting_rules; |
| 337 ContentSettingsForOneType& script_setting_rules = | 327 ContentSettingsForOneType& script_setting_rules = |
| 338 content_setting_rules.script_rules; | 328 content_setting_rules.script_rules; |
| 339 script_setting_rules.push_back(ContentSettingPatternSource( | 329 script_setting_rules.push_back(ContentSettingPatternSource( |
| 340 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), | 330 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), |
| 341 CONTENT_SETTING_BLOCK, std::string(), false)); | 331 content_settings::ContentSettingToValue(CONTENT_SETTING_BLOCK), |
| 332 std::string(), false)); |
| 342 | 333 |
| 343 ContentSettingsObserver* observer = | 334 ContentSettingsObserver* observer = |
| 344 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); | 335 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); |
| 345 observer->SetContentSettingRules(&content_setting_rules); | 336 observer->SetContentSettingRules(&content_setting_rules); |
| 346 | 337 |
| 347 // 2. Load a page which contains a noscript tag and a script tag. Note that | 338 // 2. Load a page which contains a noscript tag and a script tag. Note that |
| 348 // the page doesn't have a body tag. | 339 // the page doesn't have a body tag. |
| 349 const char kHtml[] = | 340 const char kHtml[] = |
| 350 "<html>" | 341 "<html>" |
| 351 "<noscript>JS_DISABLED</noscript>" | 342 "<noscript>JS_DISABLED</noscript>" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 362 std::string::npos, | 353 std::string::npos, |
| 363 blink::WebFrameContentDumper::DumpLayoutTreeAsText( | 354 blink::WebFrameContentDumper::DumpLayoutTreeAsText( |
| 364 GetMainFrame(), blink::WebFrameContentDumper::kLayoutAsTextNormal) | 355 GetMainFrame(), blink::WebFrameContentDumper::kLayoutAsTextNormal) |
| 365 .Utf8() | 356 .Utf8() |
| 366 .find("JS_ENABLED")); | 357 .find("JS_ENABLED")); |
| 367 | 358 |
| 368 // 3. Allow JavaScript. | 359 // 3. Allow JavaScript. |
| 369 script_setting_rules.clear(); | 360 script_setting_rules.clear(); |
| 370 script_setting_rules.push_back(ContentSettingPatternSource( | 361 script_setting_rules.push_back(ContentSettingPatternSource( |
| 371 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), | 362 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), |
| 372 CONTENT_SETTING_ALLOW, std::string(), false)); | 363 content_settings::ContentSettingToValue(CONTENT_SETTING_ALLOW), |
| 364 std::string(), false)); |
| 373 observer->SetContentSettingRules(&content_setting_rules); | 365 observer->SetContentSettingRules(&content_setting_rules); |
| 374 | 366 |
| 375 // 4. Reload the page. | 367 // 4. Reload the page. |
| 376 std::string url_str = "data:text/html;charset=utf-8,"; | 368 std::string url_str = "data:text/html;charset=utf-8,"; |
| 377 url_str.append(kHtml); | 369 url_str.append(kHtml); |
| 378 GURL url(url_str); | 370 GURL url(url_str); |
| 379 Reload(url); | 371 Reload(url); |
| 380 EXPECT_NE( | 372 EXPECT_NE( |
| 381 std::string::npos, | 373 std::string::npos, |
| 382 blink::WebFrameContentDumper::DumpLayoutTreeAsText( | 374 blink::WebFrameContentDumper::DumpLayoutTreeAsText( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 was_blocked = true; | 406 was_blocked = true; |
| 415 } | 407 } |
| 416 EXPECT_FALSE(was_blocked); | 408 EXPECT_FALSE(was_blocked); |
| 417 | 409 |
| 418 // Block JavaScript. | 410 // Block JavaScript. |
| 419 RendererContentSettingRules content_setting_rules; | 411 RendererContentSettingRules content_setting_rules; |
| 420 ContentSettingsForOneType& script_setting_rules = | 412 ContentSettingsForOneType& script_setting_rules = |
| 421 content_setting_rules.script_rules; | 413 content_setting_rules.script_rules; |
| 422 script_setting_rules.push_back(ContentSettingPatternSource( | 414 script_setting_rules.push_back(ContentSettingPatternSource( |
| 423 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), | 415 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), |
| 424 CONTENT_SETTING_BLOCK, std::string(), false)); | 416 content_settings::ContentSettingToValue(CONTENT_SETTING_BLOCK), |
| 417 std::string(), false)); |
| 425 | 418 |
| 426 ContentSettingsObserver* observer = | 419 ContentSettingsObserver* observer = |
| 427 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); | 420 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); |
| 428 observer->SetContentSettingRules(&content_setting_rules); | 421 observer->SetContentSettingRules(&content_setting_rules); |
| 429 | 422 |
| 430 // The page shouldn't see the change to script blocking setting after a | 423 // The page shouldn't see the change to script blocking setting after a |
| 431 // same document navigation. | 424 // same document navigation. |
| 432 OnSameDocumentNavigation(GetMainFrame(), true, true); | 425 OnSameDocumentNavigation(GetMainFrame(), true, true); |
| 433 EXPECT_TRUE(observer->AllowScript(true)); | 426 EXPECT_TRUE(observer->AllowScript(true)); |
| 434 } | 427 } |
| 435 | 428 |
| 436 TEST_F(ChromeRenderViewTest, ContentSettingsInterstitialPages) { | 429 TEST_F(ChromeRenderViewTest, ContentSettingsInterstitialPages) { |
| 437 MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame()); | 430 MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame()); |
| 438 // Block scripts. | 431 // Block scripts. |
| 439 RendererContentSettingRules content_setting_rules; | 432 RendererContentSettingRules content_setting_rules; |
| 440 ContentSettingsForOneType& script_setting_rules = | 433 ContentSettingsForOneType& script_setting_rules = |
| 441 content_setting_rules.script_rules; | 434 content_setting_rules.script_rules; |
| 442 script_setting_rules.push_back( | 435 script_setting_rules.push_back(ContentSettingPatternSource( |
| 443 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 436 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), |
| 444 ContentSettingsPattern::Wildcard(), | 437 content_settings::ContentSettingToValue(CONTENT_SETTING_BLOCK), |
| 445 CONTENT_SETTING_BLOCK, | 438 std::string(), false)); |
| 446 std::string(), | |
| 447 false)); | |
| 448 // Block images. | 439 // Block images. |
| 449 ContentSettingsForOneType& image_setting_rules = | 440 ContentSettingsForOneType& image_setting_rules = |
| 450 content_setting_rules.image_rules; | 441 content_setting_rules.image_rules; |
| 451 image_setting_rules.push_back( | 442 image_setting_rules.push_back(ContentSettingPatternSource( |
| 452 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 443 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), |
| 453 ContentSettingsPattern::Wildcard(), | 444 content_settings::ContentSettingToValue(CONTENT_SETTING_BLOCK), |
| 454 CONTENT_SETTING_BLOCK, | 445 std::string(), false)); |
| 455 std::string(), | |
| 456 false)); | |
| 457 | 446 |
| 458 ContentSettingsObserver* observer = | 447 ContentSettingsObserver* observer = |
| 459 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); | 448 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); |
| 460 observer->SetContentSettingRules(&content_setting_rules); | 449 observer->SetContentSettingRules(&content_setting_rules); |
| 461 observer->OnSetAsInterstitial(); | 450 observer->OnSetAsInterstitial(); |
| 462 | 451 |
| 463 // Load a page which contains a script. | 452 // Load a page which contains a script. |
| 464 const char kHtml[] = | 453 const char kHtml[] = |
| 465 "<html>" | 454 "<html>" |
| 466 "<head>" | 455 "<head>" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 490 TEST_F(ChromeRenderViewTest, AutoplayContentSettings) { | 479 TEST_F(ChromeRenderViewTest, AutoplayContentSettings) { |
| 491 MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame()); | 480 MockContentSettingsObserver mock_observer(view_->GetMainRenderFrame()); |
| 492 | 481 |
| 493 // Load some HTML. | 482 // Load some HTML. |
| 494 LoadHTML("<html>Foo</html>"); | 483 LoadHTML("<html>Foo</html>"); |
| 495 | 484 |
| 496 // Set the default setting. | 485 // Set the default setting. |
| 497 RendererContentSettingRules content_setting_rules; | 486 RendererContentSettingRules content_setting_rules; |
| 498 ContentSettingsForOneType& autoplay_setting_rules = | 487 ContentSettingsForOneType& autoplay_setting_rules = |
| 499 content_setting_rules.autoplay_rules; | 488 content_setting_rules.autoplay_rules; |
| 500 autoplay_setting_rules.push_back( | 489 autoplay_setting_rules.push_back(ContentSettingPatternSource( |
| 501 ContentSettingPatternSource(ContentSettingsPattern::Wildcard(), | 490 ContentSettingsPattern::Wildcard(), ContentSettingsPattern::Wildcard(), |
| 502 ContentSettingsPattern::Wildcard(), | 491 content_settings::ContentSettingToValue(CONTENT_SETTING_ALLOW), |
| 503 CONTENT_SETTING_ALLOW, | 492 std::string(), false)); |
| 504 std::string(), | |
| 505 false)); | |
| 506 | 493 |
| 507 ContentSettingsObserver* observer = | 494 ContentSettingsObserver* observer = |
| 508 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); | 495 ContentSettingsObserver::Get(view_->GetMainRenderFrame()); |
| 509 observer->SetContentSettingRules(&content_setting_rules); | 496 observer->SetContentSettingRules(&content_setting_rules); |
| 510 | 497 |
| 511 EXPECT_TRUE(observer->AllowAutoplay(false)); | 498 EXPECT_TRUE(observer->AllowAutoplay(false)); |
| 512 ::testing::Mock::VerifyAndClearExpectations(&observer); | 499 ::testing::Mock::VerifyAndClearExpectations(&observer); |
| 513 | 500 |
| 514 // Add rule to block autoplay. | 501 // Add rule to block autoplay. |
| 515 autoplay_setting_rules.insert( | 502 autoplay_setting_rules.insert( |
| 516 autoplay_setting_rules.begin(), | 503 autoplay_setting_rules.begin(), |
| 517 ContentSettingPatternSource( | 504 ContentSettingPatternSource( |
| 518 ContentSettingsPattern::Wildcard(), | 505 ContentSettingsPattern::Wildcard(), |
| 519 ContentSettingsPattern::Wildcard(), | 506 ContentSettingsPattern::Wildcard(), |
| 520 CONTENT_SETTING_BLOCK, | 507 content_settings::ContentSettingToValue(CONTENT_SETTING_BLOCK), |
| 521 std::string(), | 508 std::string(), false)); |
| 522 false)); | |
| 523 | 509 |
| 524 EXPECT_FALSE(observer->AllowAutoplay(true)); | 510 EXPECT_FALSE(observer->AllowAutoplay(true)); |
| 525 ::testing::Mock::VerifyAndClearExpectations(&observer); | 511 ::testing::Mock::VerifyAndClearExpectations(&observer); |
| 526 } | 512 } |
| OLD | NEW |