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 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 content_setting_bubble_model->bubble_content().radio_group.radio_items[0]; | 552 content_setting_bubble_model->bubble_content().radio_group.radio_items[0]; |
553 ASSERT_NE(std::string::npos, title.find(file_url)); | 553 ASSERT_NE(std::string::npos, title.find(file_url)); |
554 } | 554 } |
555 | 555 |
556 TEST_F(ContentSettingBubbleModelTest, RegisterProtocolHandler) { | 556 TEST_F(ContentSettingBubbleModelTest, RegisterProtocolHandler) { |
557 const GURL page_url("http://toplevel.example/"); | 557 const GURL page_url("http://toplevel.example/"); |
558 NavigateAndCommit(page_url); | 558 NavigateAndCommit(page_url); |
559 TabSpecificContentSettings* content_settings = | 559 TabSpecificContentSettings* content_settings = |
560 TabSpecificContentSettings::FromWebContents(web_contents()); | 560 TabSpecificContentSettings::FromWebContents(web_contents()); |
561 content_settings->set_pending_protocol_handler( | 561 content_settings->set_pending_protocol_handler( |
562 ProtocolHandler::CreateProtocolHandler("mailto", | 562 ProtocolHandler::CreateProtocolHandler( |
563 GURL("http://www.toplevel.example/"), base::ASCIIToUTF16("Handler"))); | 563 "mailto", GURL("http://www.toplevel.example/"))); |
564 | 564 |
565 ContentSettingRPHBubbleModel content_setting_bubble_model( | 565 ContentSettingRPHBubbleModel content_setting_bubble_model( |
566 NULL, web_contents(), profile(), NULL, | 566 NULL, web_contents(), profile(), NULL, |
567 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS); | 567 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS); |
568 | 568 |
569 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 569 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
570 content_setting_bubble_model.bubble_content(); | 570 content_setting_bubble_model.bubble_content(); |
571 EXPECT_FALSE(bubble_content.title.empty()); | 571 EXPECT_FALSE(bubble_content.title.empty()); |
572 EXPECT_FALSE(bubble_content.radio_group.radio_items.empty()); | 572 EXPECT_FALSE(bubble_content.radio_group.radio_items.empty()); |
573 EXPECT_TRUE(bubble_content.popup_items.empty()); | 573 EXPECT_TRUE(bubble_content.popup_items.empty()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 606 |
607 TEST_F(ContentSettingBubbleModelTest, RPHAllow) { | 607 TEST_F(ContentSettingBubbleModelTest, RPHAllow) { |
608 ProtocolHandlerRegistry registry(profile(), new FakeDelegate()); | 608 ProtocolHandlerRegistry registry(profile(), new FakeDelegate()); |
609 registry.InitProtocolSettings(); | 609 registry.InitProtocolSettings(); |
610 | 610 |
611 const GURL page_url("http://toplevel.example/"); | 611 const GURL page_url("http://toplevel.example/"); |
612 NavigateAndCommit(page_url); | 612 NavigateAndCommit(page_url); |
613 TabSpecificContentSettings* content_settings = | 613 TabSpecificContentSettings* content_settings = |
614 TabSpecificContentSettings::FromWebContents(web_contents()); | 614 TabSpecificContentSettings::FromWebContents(web_contents()); |
615 ProtocolHandler test_handler = ProtocolHandler::CreateProtocolHandler( | 615 ProtocolHandler test_handler = ProtocolHandler::CreateProtocolHandler( |
616 "mailto", GURL("http://www.toplevel.example/"), | 616 "mailto", GURL("http://www.toplevel.example/")); |
617 base::ASCIIToUTF16("Handler")); | |
618 content_settings->set_pending_protocol_handler(test_handler); | 617 content_settings->set_pending_protocol_handler(test_handler); |
619 | 618 |
620 ContentSettingRPHBubbleModel content_setting_bubble_model( | 619 ContentSettingRPHBubbleModel content_setting_bubble_model( |
621 NULL, web_contents(), profile(), ®istry, | 620 NULL, web_contents(), profile(), ®istry, |
622 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS); | 621 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS); |
623 | 622 |
624 { | 623 { |
625 ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 624 ProtocolHandler handler = registry.GetHandlerFor("mailto"); |
626 EXPECT_TRUE(handler.IsEmpty()); | 625 EXPECT_TRUE(handler.IsEmpty()); |
627 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 626 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
628 content_settings->pending_protocol_handler_setting()); | 627 content_settings->pending_protocol_handler_setting()); |
629 } | 628 } |
630 | 629 |
631 // "0" is the "Allow" radio button. | 630 // "0" is the "Allow" radio button. |
632 content_setting_bubble_model.OnRadioClicked(0); | 631 content_setting_bubble_model.OnRadioClicked(0); |
633 { | 632 { |
634 ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 633 ProtocolHandler handler = registry.GetHandlerFor("mailto"); |
635 ASSERT_FALSE(handler.IsEmpty()); | 634 ASSERT_FALSE(handler.IsEmpty()); |
636 EXPECT_EQ(base::ASCIIToUTF16("Handler"), handler.title()); | |
637 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 635 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
638 content_settings->pending_protocol_handler_setting()); | 636 content_settings->pending_protocol_handler_setting()); |
639 } | 637 } |
640 | 638 |
641 // "1" is the "Deny" radio button. | 639 // "1" is the "Deny" radio button. |
642 content_setting_bubble_model.OnRadioClicked(1); | 640 content_setting_bubble_model.OnRadioClicked(1); |
643 { | 641 { |
644 ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 642 ProtocolHandler handler = registry.GetHandlerFor("mailto"); |
645 EXPECT_TRUE(handler.IsEmpty()); | 643 EXPECT_TRUE(handler.IsEmpty()); |
646 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 644 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
647 content_settings->pending_protocol_handler_setting()); | 645 content_settings->pending_protocol_handler_setting()); |
648 } | 646 } |
649 | 647 |
650 // "2" is the "Ignore button. | 648 // "2" is the "Ignore button. |
651 content_setting_bubble_model.OnRadioClicked(2); | 649 content_setting_bubble_model.OnRadioClicked(2); |
652 { | 650 { |
653 ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 651 ProtocolHandler handler = registry.GetHandlerFor("mailto"); |
654 EXPECT_TRUE(handler.IsEmpty()); | 652 EXPECT_TRUE(handler.IsEmpty()); |
655 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 653 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
656 content_settings->pending_protocol_handler_setting()); | 654 content_settings->pending_protocol_handler_setting()); |
657 EXPECT_TRUE(registry.IsIgnored(test_handler)); | 655 EXPECT_TRUE(registry.IsIgnored(test_handler)); |
658 } | 656 } |
659 | 657 |
660 // "0" is the "Allow" radio button. | 658 // "0" is the "Allow" radio button. |
661 content_setting_bubble_model.OnRadioClicked(0); | 659 content_setting_bubble_model.OnRadioClicked(0); |
662 { | 660 { |
663 ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 661 ProtocolHandler handler = registry.GetHandlerFor("mailto"); |
664 ASSERT_FALSE(handler.IsEmpty()); | 662 ASSERT_FALSE(handler.IsEmpty()); |
665 EXPECT_EQ(base::ASCIIToUTF16("Handler"), handler.title()); | |
666 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 663 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
667 content_settings->pending_protocol_handler_setting()); | 664 content_settings->pending_protocol_handler_setting()); |
668 EXPECT_FALSE(registry.IsIgnored(test_handler)); | 665 EXPECT_FALSE(registry.IsIgnored(test_handler)); |
669 } | 666 } |
670 | 667 |
671 registry.Shutdown(); | 668 registry.Shutdown(); |
672 } | 669 } |
OLD | NEW |