| 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 "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 10 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 10 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 EXPECT_NE(expect_clear_link || expect_reload_hint, | 49 EXPECT_NE(expect_clear_link || expect_reload_hint, |
| 50 bubble_content.custom_link.empty()); | 50 bubble_content.custom_link.empty()); |
| 51 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled); | 51 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled); |
| 52 EXPECT_FALSE(bubble_content.manage_link.empty()); | 52 EXPECT_FALSE(bubble_content.manage_link.empty()); |
| 53 } | 53 } |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 TEST_F(ContentSettingBubbleModelTest, ImageRadios) { | 56 TEST_F(ContentSettingBubbleModelTest, ImageRadios) { |
| 57 TabSpecificContentSettings* content_settings = | 57 TabSpecificContentSettings* content_settings = |
| 58 TabSpecificContentSettings::FromWebContents(web_contents()); | 58 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 59 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, | 59 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES); |
| 60 std::string()); | |
| 61 | 60 |
| 62 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 61 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 63 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 62 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 64 NULL, web_contents(), profile(), | 63 NULL, web_contents(), profile(), |
| 65 CONTENT_SETTINGS_TYPE_IMAGES)); | 64 CONTENT_SETTINGS_TYPE_IMAGES)); |
| 66 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 65 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 67 content_setting_bubble_model->bubble_content(); | 66 content_setting_bubble_model->bubble_content(); |
| 68 EXPECT_FALSE(bubble_content.title.empty()); | 67 EXPECT_FALSE(bubble_content.title.empty()); |
| 69 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); | 68 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); |
| 70 EXPECT_EQ(0, bubble_content.radio_group.default_item); | 69 EXPECT_EQ(0, bubble_content.radio_group.default_item); |
| 71 EXPECT_TRUE(bubble_content.custom_link.empty()); | 70 EXPECT_TRUE(bubble_content.custom_link.empty()); |
| 72 EXPECT_FALSE(bubble_content.manage_link.empty()); | 71 EXPECT_FALSE(bubble_content.manage_link.empty()); |
| 73 } | 72 } |
| 74 | 73 |
| 75 TEST_F(ContentSettingBubbleModelTest, Cookies) { | 74 TEST_F(ContentSettingBubbleModelTest, Cookies) { |
| 76 TabSpecificContentSettings* content_settings = | 75 TabSpecificContentSettings* content_settings = |
| 77 TabSpecificContentSettings::FromWebContents(web_contents()); | 76 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 78 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, | 77 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); |
| 79 std::string()); | |
| 80 | 78 |
| 81 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 79 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 82 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 80 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 83 NULL, web_contents(), profile(), CONTENT_SETTINGS_TYPE_COOKIES)); | 81 NULL, web_contents(), profile(), CONTENT_SETTINGS_TYPE_COOKIES)); |
| 84 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 82 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 85 content_setting_bubble_model->bubble_content(); | 83 content_setting_bubble_model->bubble_content(); |
| 86 std::string title = bubble_content.title; | 84 std::string title = bubble_content.title; |
| 87 EXPECT_FALSE(title.empty()); | 85 EXPECT_FALSE(title.empty()); |
| 88 ASSERT_EQ(2U, bubble_content.radio_group.radio_items.size()); | 86 ASSERT_EQ(2U, bubble_content.radio_group.radio_items.size()); |
| 89 std::string radio1 = bubble_content.radio_group.radio_items[0]; | 87 std::string radio1 = bubble_content.radio_group.radio_items[0]; |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 EXPECT_EQ(new_bubble_content.radio_group.radio_items[1], | 440 EXPECT_EQ(new_bubble_content.radio_group.radio_items[1], |
| 443 l10n_util::GetStringUTF8( | 441 l10n_util::GetStringUTF8( |
| 444 IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_BLOCK)); | 442 IDS_ALLOWED_MEDIASTREAM_MIC_AND_CAMERA_BLOCK)); |
| 445 EXPECT_EQ(0, new_bubble_content.radio_group.default_item); | 443 EXPECT_EQ(0, new_bubble_content.radio_group.default_item); |
| 446 EXPECT_EQ(2U, new_bubble_content.media_menus.size()); | 444 EXPECT_EQ(2U, new_bubble_content.media_menus.size()); |
| 447 } | 445 } |
| 448 | 446 |
| 449 TEST_F(ContentSettingBubbleModelTest, Plugins) { | 447 TEST_F(ContentSettingBubbleModelTest, Plugins) { |
| 450 TabSpecificContentSettings* content_settings = | 448 TabSpecificContentSettings* content_settings = |
| 451 TabSpecificContentSettings::FromWebContents(web_contents()); | 449 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 452 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, | 450 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS); |
| 453 std::string()); | |
| 454 | 451 |
| 455 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 452 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 456 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 453 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 457 NULL, web_contents(), profile(), | 454 NULL, web_contents(), profile(), |
| 458 CONTENT_SETTINGS_TYPE_PLUGINS)); | 455 CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 459 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 456 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 460 content_setting_bubble_model->bubble_content(); | 457 content_setting_bubble_model->bubble_content(); |
| 461 EXPECT_FALSE(bubble_content.title.empty()); | 458 EXPECT_FALSE(bubble_content.title.empty()); |
| 462 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); | 459 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); |
| 463 EXPECT_FALSE(bubble_content.custom_link.empty()); | 460 EXPECT_FALSE(bubble_content.custom_link.empty()); |
| 464 EXPECT_TRUE(bubble_content.custom_link_enabled); | 461 EXPECT_TRUE(bubble_content.custom_link_enabled); |
| 465 EXPECT_FALSE(bubble_content.manage_link.empty()); | 462 EXPECT_FALSE(bubble_content.manage_link.empty()); |
| 466 } | 463 } |
| 467 | 464 |
| 468 TEST_F(ContentSettingBubbleModelTest, MultiplePlugins) { | |
| 469 CommandLine* cmd = CommandLine::ForCurrentProcess(); | |
| 470 base::AutoReset<CommandLine> auto_reset(cmd, *cmd); | |
| 471 cmd->AppendSwitch(switches::kEnableResourceContentSettings); | |
| 472 | |
| 473 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); | |
| 474 std::string fooPlugin = "foo"; | |
| 475 std::string barPlugin = "bar"; | |
| 476 | |
| 477 // Navigating to some sample url prevents the GetURL method from returning an | |
| 478 // invalid empty URL. | |
| 479 WebContentsTester::For(web_contents())-> | |
| 480 NavigateAndCommit(GURL("http://www.example.com")); | |
| 481 GURL url = web_contents()->GetURL(); | |
| 482 map->AddExceptionForURL(url, | |
| 483 url, | |
| 484 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 485 fooPlugin, | |
| 486 CONTENT_SETTING_ALLOW); | |
| 487 map->AddExceptionForURL(url, | |
| 488 url, | |
| 489 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 490 barPlugin, | |
| 491 CONTENT_SETTING_ASK); | |
| 492 | |
| 493 TabSpecificContentSettings* content_settings = | |
| 494 TabSpecificContentSettings::FromWebContents(web_contents()); | |
| 495 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 496 fooPlugin); | |
| 497 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 498 barPlugin); | |
| 499 | |
| 500 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | |
| 501 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | |
| 502 NULL, web_contents(), profile(), | |
| 503 CONTENT_SETTINGS_TYPE_PLUGINS)); | |
| 504 const ContentSettingBubbleModel::BubbleContent& bubble_content = | |
| 505 content_setting_bubble_model->bubble_content(); | |
| 506 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); | |
| 507 EXPECT_EQ(1, bubble_content.radio_group.default_item); | |
| 508 | |
| 509 content_setting_bubble_model->OnRadioClicked(0); | |
| 510 // Nothing should have changed. | |
| 511 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 512 map->GetContentSetting(url, | |
| 513 url, | |
| 514 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 515 fooPlugin)); | |
| 516 EXPECT_EQ(CONTENT_SETTING_ASK, | |
| 517 map->GetContentSetting(url, | |
| 518 url, | |
| 519 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 520 barPlugin)); | |
| 521 | |
| 522 content_setting_bubble_model.reset(); | |
| 523 // Both plug-ins should be click-to-play now. | |
| 524 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 525 map->GetContentSetting(url, | |
| 526 url, | |
| 527 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 528 fooPlugin)); | |
| 529 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 530 map->GetContentSetting(url, | |
| 531 url, | |
| 532 CONTENT_SETTINGS_TYPE_PLUGINS, | |
| 533 barPlugin)); | |
| 534 } | |
| 535 | |
| 536 TEST_F(ContentSettingBubbleModelTest, PepperBroker) { | 465 TEST_F(ContentSettingBubbleModelTest, PepperBroker) { |
| 537 TabSpecificContentSettings* content_settings = | 466 TabSpecificContentSettings* content_settings = |
| 538 TabSpecificContentSettings::FromWebContents(web_contents()); | 467 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 539 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PPAPI_BROKER, | 468 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PPAPI_BROKER); |
| 540 std::string()); | |
| 541 | 469 |
| 542 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 470 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 543 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 471 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 544 NULL, web_contents(), profile(), | 472 NULL, web_contents(), profile(), |
| 545 CONTENT_SETTINGS_TYPE_PPAPI_BROKER)); | 473 CONTENT_SETTINGS_TYPE_PPAPI_BROKER)); |
| 546 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 474 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 547 content_setting_bubble_model->bubble_content(); | 475 content_setting_bubble_model->bubble_content(); |
| 548 | 476 |
| 549 std::string title = bubble_content.title; | 477 std::string title = bubble_content.title; |
| 550 EXPECT_FALSE(title.empty()); | 478 EXPECT_FALSE(title.empty()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 // Change the default to block: offer a clear link for the persisted frame 1. | 536 // Change the default to block: offer a clear link for the persisted frame 1. |
| 609 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 537 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
| 610 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK); | 538 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK); |
| 611 CheckGeolocationBubble(2, true, false); | 539 CheckGeolocationBubble(2, true, false); |
| 612 } | 540 } |
| 613 | 541 |
| 614 TEST_F(ContentSettingBubbleModelTest, FileURL) { | 542 TEST_F(ContentSettingBubbleModelTest, FileURL) { |
| 615 std::string file_url("file:///tmp/test.html"); | 543 std::string file_url("file:///tmp/test.html"); |
| 616 NavigateAndCommit(GURL(file_url)); | 544 NavigateAndCommit(GURL(file_url)); |
| 617 TabSpecificContentSettings::FromWebContents(web_contents())->OnContentBlocked( | 545 TabSpecificContentSettings::FromWebContents(web_contents())->OnContentBlocked( |
| 618 CONTENT_SETTINGS_TYPE_IMAGES, std::string()); | 546 CONTENT_SETTINGS_TYPE_IMAGES); |
| 619 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 547 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 620 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 548 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 621 NULL, web_contents(), profile(), | 549 NULL, web_contents(), profile(), |
| 622 CONTENT_SETTINGS_TYPE_IMAGES)); | 550 CONTENT_SETTINGS_TYPE_IMAGES)); |
| 623 std::string title = | 551 std::string title = |
| 624 content_setting_bubble_model->bubble_content().radio_group.radio_items[0]; | 552 content_setting_bubble_model->bubble_content().radio_group.radio_items[0]; |
| 625 ASSERT_NE(std::string::npos, title.find(file_url)); | 553 ASSERT_NE(std::string::npos, title.find(file_url)); |
| 626 } | 554 } |
| 627 | 555 |
| 628 TEST_F(ContentSettingBubbleModelTest, RegisterProtocolHandler) { | 556 TEST_F(ContentSettingBubbleModelTest, RegisterProtocolHandler) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 663 ProtocolHandler handler = registry.GetHandlerFor("mailto"); |
| 736 ASSERT_FALSE(handler.IsEmpty()); | 664 ASSERT_FALSE(handler.IsEmpty()); |
| 737 EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title()); | 665 EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title()); |
| 738 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 666 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 739 content_settings->pending_protocol_handler_setting()); | 667 content_settings->pending_protocol_handler_setting()); |
| 740 EXPECT_FALSE(registry.IsIgnored(test_handler)); | 668 EXPECT_FALSE(registry.IsIgnored(test_handler)); |
| 741 } | 669 } |
| 742 | 670 |
| 743 registry.Shutdown(); | 671 registry.Shutdown(); |
| 744 } | 672 } |
| OLD | NEW |