| 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/utf_string_conversions.h" |    7 #include "base/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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  244  |  244  | 
|  245 TEST_F(ContentSettingBubbleModelTest, RegisterProtocolHandler) { |  245 TEST_F(ContentSettingBubbleModelTest, RegisterProtocolHandler) { | 
|  246   const GURL page_url("http://toplevel.example/"); |  246   const GURL page_url("http://toplevel.example/"); | 
|  247   NavigateAndCommit(page_url); |  247   NavigateAndCommit(page_url); | 
|  248   TabSpecificContentSettings* content_settings = |  248   TabSpecificContentSettings* content_settings = | 
|  249       tab_contents()->content_settings(); |  249       tab_contents()->content_settings(); | 
|  250   content_settings->set_pending_protocol_handler( |  250   content_settings->set_pending_protocol_handler( | 
|  251       ProtocolHandler::CreateProtocolHandler("mailto", |  251       ProtocolHandler::CreateProtocolHandler("mailto", | 
|  252           GURL("http://www.toplevel.example/"), ASCIIToUTF16("Handler"))); |  252           GURL("http://www.toplevel.example/"), ASCIIToUTF16("Handler"))); | 
|  253  |  253  | 
|  254   scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |  254   ContentSettingRPHBubbleModel content_setting_bubble_model( | 
|  255       ContentSettingBubbleModel::CreateContentSettingBubbleModel( |  255           NULL, tab_contents(), profile(), NULL, | 
|  256           NULL, tab_contents(), profile(), |  256           CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS); | 
|  257           CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS)); |  257  | 
|  258   const ContentSettingBubbleModel::BubbleContent& bubble_content = |  258   const ContentSettingBubbleModel::BubbleContent& bubble_content = | 
|  259       content_setting_bubble_model->bubble_content(); |  259       content_setting_bubble_model.bubble_content(); | 
|  260   EXPECT_FALSE(bubble_content.title.empty()); |  260   EXPECT_FALSE(bubble_content.title.empty()); | 
|  261   EXPECT_FALSE(bubble_content.radio_group.radio_items.empty()); |  261   EXPECT_FALSE(bubble_content.radio_group.radio_items.empty()); | 
|  262   EXPECT_TRUE(bubble_content.popup_items.empty()); |  262   EXPECT_TRUE(bubble_content.popup_items.empty()); | 
|  263   EXPECT_TRUE(bubble_content.domain_lists.empty()); |  263   EXPECT_TRUE(bubble_content.domain_lists.empty()); | 
|  264   EXPECT_TRUE(bubble_content.custom_link.empty()); |  264   EXPECT_TRUE(bubble_content.custom_link.empty()); | 
|  265   EXPECT_FALSE(bubble_content.custom_link_enabled); |  265   EXPECT_FALSE(bubble_content.custom_link_enabled); | 
|  266   EXPECT_FALSE(bubble_content.manage_link.empty()); |  266   EXPECT_FALSE(bubble_content.manage_link.empty()); | 
|  267 } |  267 } | 
|  268  |  268  | 
|  269 class FakeDelegate : public ProtocolHandlerRegistry::Delegate { |  269 class FakeDelegate : public ProtocolHandlerRegistry::Delegate { | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  288  |  288  | 
|  289   virtual void RegisterWithOSAsDefaultClient( |  289   virtual void RegisterWithOSAsDefaultClient( | 
|  290       const std::string& protocol, |  290       const std::string& protocol, | 
|  291       ProtocolHandlerRegistry* registry) { |  291       ProtocolHandlerRegistry* registry) { | 
|  292     LOG(INFO) << "Register With OS"; |  292     LOG(INFO) << "Register With OS"; | 
|  293   } |  293   } | 
|  294 }; |  294 }; | 
|  295  |  295  | 
|  296 TEST_F(ContentSettingBubbleModelTest, RPHAllow) { |  296 TEST_F(ContentSettingBubbleModelTest, RPHAllow) { | 
|  297   StartIOThread(); |  297   StartIOThread(); | 
|  298   profile()->CreateProtocolHandlerRegistry(new FakeDelegate); |  298  | 
 |  299   ProtocolHandlerRegistry registry(profile(), new FakeDelegate()); | 
 |  300   registry.InitProtocolSettings(); | 
|  299  |  301  | 
|  300   const GURL page_url("http://toplevel.example/"); |  302   const GURL page_url("http://toplevel.example/"); | 
|  301   NavigateAndCommit(page_url); |  303   NavigateAndCommit(page_url); | 
|  302   TabSpecificContentSettings* content_settings = |  304   TabSpecificContentSettings* content_settings = | 
|  303       tab_contents()->content_settings(); |  305       tab_contents()->content_settings(); | 
|  304   ProtocolHandler test_handler = ProtocolHandler::CreateProtocolHandler( |  306   ProtocolHandler test_handler = ProtocolHandler::CreateProtocolHandler( | 
|  305       "mailto", GURL("http://www.toplevel.example/"), |  307       "mailto", GURL("http://www.toplevel.example/"), | 
|  306       ASCIIToUTF16("Handler")); |  308       ASCIIToUTF16("Handler")); | 
|  307   content_settings->set_pending_protocol_handler(test_handler); |  309   content_settings->set_pending_protocol_handler(test_handler); | 
|  308  |  310  | 
|  309   scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |  311   ContentSettingRPHBubbleModel content_setting_bubble_model( | 
|  310       ContentSettingBubbleModel::CreateContentSettingBubbleModel( |  312           NULL, tab_contents(), profile(), ®istry, | 
|  311           NULL, tab_contents(), profile(), |  313           CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS); | 
|  312           CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS)); |  | 
|  313  |  314  | 
|  314   { |  315   { | 
|  315     ProtocolHandler handler = |  316     ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 
|  316         profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); |  | 
|  317     EXPECT_TRUE(handler.IsEmpty()); |  317     EXPECT_TRUE(handler.IsEmpty()); | 
|  318     EXPECT_EQ(CONTENT_SETTING_DEFAULT, |  318     EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 
|  319               content_settings->pending_protocol_handler_setting()); |  319               content_settings->pending_protocol_handler_setting()); | 
|  320   } |  320   } | 
|  321  |  321  | 
|  322   // "0" is the "Allow" radio button. |  322   // "0" is the "Allow" radio button. | 
|  323   content_setting_bubble_model->OnRadioClicked(0); |  323   content_setting_bubble_model.OnRadioClicked(0); | 
|  324   { |  324   { | 
|  325     ProtocolHandler handler = |  325     ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 
|  326         profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); |  | 
|  327     ASSERT_FALSE(handler.IsEmpty()); |  326     ASSERT_FALSE(handler.IsEmpty()); | 
|  328     EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title()); |  327     EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title()); | 
|  329     EXPECT_EQ(CONTENT_SETTING_ALLOW, |  328     EXPECT_EQ(CONTENT_SETTING_ALLOW, | 
|  330               content_settings->pending_protocol_handler_setting()); |  329               content_settings->pending_protocol_handler_setting()); | 
|  331   } |  330   } | 
|  332  |  331  | 
|  333   // "1" is the "Deny" radio button. |  332   // "1" is the "Deny" radio button. | 
|  334   content_setting_bubble_model->OnRadioClicked(1); |  333   content_setting_bubble_model.OnRadioClicked(1); | 
|  335   { |  334   { | 
|  336     ProtocolHandler handler = |  335     ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 
|  337         profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); |  | 
|  338     EXPECT_TRUE(handler.IsEmpty()); |  336     EXPECT_TRUE(handler.IsEmpty()); | 
|  339     EXPECT_EQ(CONTENT_SETTING_BLOCK, |  337     EXPECT_EQ(CONTENT_SETTING_BLOCK, | 
|  340               content_settings->pending_protocol_handler_setting()); |  338               content_settings->pending_protocol_handler_setting()); | 
|  341   } |  339   } | 
|  342  |  340  | 
|  343   // "2" is the "Ignore button. |  341   // "2" is the "Ignore button. | 
|  344   content_setting_bubble_model->OnRadioClicked(2); |  342   content_setting_bubble_model.OnRadioClicked(2); | 
|  345   { |  343   { | 
|  346     ProtocolHandler handler = |  344     ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 
|  347         profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); |  | 
|  348     EXPECT_TRUE(handler.IsEmpty()); |  345     EXPECT_TRUE(handler.IsEmpty()); | 
|  349     EXPECT_EQ(CONTENT_SETTING_DEFAULT, |  346     EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 
|  350               content_settings->pending_protocol_handler_setting()); |  347               content_settings->pending_protocol_handler_setting()); | 
|  351     EXPECT_TRUE(profile()->GetProtocolHandlerRegistry()->IsIgnored( |  348     EXPECT_TRUE(registry.IsIgnored(test_handler)); | 
|  352         test_handler)); |  | 
|  353   } |  349   } | 
|  354  |  350  | 
|  355   // "0" is the "Allow" radio button. |  351   // "0" is the "Allow" radio button. | 
|  356   content_setting_bubble_model->OnRadioClicked(0); |  352   content_setting_bubble_model.OnRadioClicked(0); | 
|  357   { |  353   { | 
|  358     ProtocolHandler handler = |  354     ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 
|  359         profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); |  | 
|  360     ASSERT_FALSE(handler.IsEmpty()); |  355     ASSERT_FALSE(handler.IsEmpty()); | 
|  361     EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title()); |  356     EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title()); | 
|  362     EXPECT_EQ(CONTENT_SETTING_ALLOW, |  357     EXPECT_EQ(CONTENT_SETTING_ALLOW, | 
|  363               content_settings->pending_protocol_handler_setting()); |  358               content_settings->pending_protocol_handler_setting()); | 
|  364     EXPECT_FALSE(profile()->GetProtocolHandlerRegistry()->IsIgnored( |  359     EXPECT_FALSE(registry.IsIgnored(test_handler)); | 
|  365         test_handler)); |  | 
|  366   } |  360   } | 
|  367  |  361  | 
|  368   // This must be done on the UI thread. |  362   registry.Shutdown(); | 
|  369   profile()->GetProtocolHandlerRegistry()->Finalize(); |  | 
|  370 } |  363 } | 
| OLD | NEW |