| 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 "chrome/browser/content_settings/host_content_settings_map.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 8 #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" |
| 9 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 12 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 12 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" | 14 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" |
| 13 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/content_settings.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 15 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
| 17 #include "content/public/test/web_contents_tester.h" | 20 #include "content/public/test/web_contents_tester.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 22 |
| 20 using content::BrowserThread; | 23 using content::BrowserThread; |
| 21 using content::WebContentsTester; | 24 using content::WebContentsTester; |
| 22 | 25 |
| 23 class ContentSettingBubbleModelTest : public TabContentsTestHarness { | 26 class ContentSettingBubbleModelTest : public TabContentsTestHarness { |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 std::string file_url("file:///tmp/test.html"); | 216 std::string file_url("file:///tmp/test.html"); |
| 214 NavigateAndCommit(GURL(file_url)); | 217 NavigateAndCommit(GURL(file_url)); |
| 215 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 218 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 216 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 219 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 217 NULL, tab_contents(), profile(), | 220 NULL, tab_contents(), profile(), |
| 218 CONTENT_SETTINGS_TYPE_IMAGES)); | 221 CONTENT_SETTINGS_TYPE_IMAGES)); |
| 219 std::string title = | 222 std::string title = |
| 220 content_setting_bubble_model->bubble_content().radio_group.radio_items[0]; | 223 content_setting_bubble_model->bubble_content().radio_group.radio_items[0]; |
| 221 ASSERT_NE(std::string::npos, title.find(file_url)); | 224 ASSERT_NE(std::string::npos, title.find(file_url)); |
| 222 } | 225 } |
| 226 |
| 227 TEST_F(ContentSettingBubbleModelTest, RegisterProtocolHandler) { |
| 228 const GURL page_url("http://toplevel.example/"); |
| 229 NavigateAndCommit(page_url); |
| 230 TabSpecificContentSettings* content_settings = |
| 231 tab_contents()->content_settings(); |
| 232 content_settings->set_pending_protocol_handler( |
| 233 ProtocolHandler::CreateProtocolHandler("mailto", |
| 234 GURL("http://www.toplevel.example/"), ASCIIToUTF16("Handler"))); |
| 235 |
| 236 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 237 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 238 NULL, tab_contents(), profile(), |
| 239 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS)); |
| 240 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 241 content_setting_bubble_model->bubble_content(); |
| 242 EXPECT_FALSE(bubble_content.title.empty()); |
| 243 EXPECT_FALSE(bubble_content.radio_group.radio_items.empty()); |
| 244 EXPECT_TRUE(bubble_content.popup_items.empty()); |
| 245 EXPECT_TRUE(bubble_content.domain_lists.empty()); |
| 246 EXPECT_TRUE(bubble_content.custom_link.empty()); |
| 247 EXPECT_FALSE(bubble_content.custom_link_enabled); |
| 248 EXPECT_FALSE(bubble_content.manage_link.empty()); |
| 249 } |
| 250 |
| 251 class FakeDelegate : public ProtocolHandlerRegistry::Delegate { |
| 252 public: |
| 253 virtual void RegisterExternalHandler(const std::string& protocol) { |
| 254 // Overrides in order to not register the handler with the |
| 255 // ChildProcessSecurityPolicy. That has persistent and unalterable |
| 256 // side effects on other tests. |
| 257 } |
| 258 }; |
| 259 |
| 260 TEST_F(ContentSettingBubbleModelTest, RPHAllow) { |
| 261 profile()->CreateProtocolHandlerRegistry(new FakeDelegate); |
| 262 |
| 263 const GURL page_url("http://toplevel.example/"); |
| 264 NavigateAndCommit(page_url); |
| 265 TabSpecificContentSettings* content_settings = |
| 266 tab_contents()->content_settings(); |
| 267 ProtocolHandler test_handler = ProtocolHandler::CreateProtocolHandler( |
| 268 "mailto", GURL("http://www.toplevel.example/"), |
| 269 ASCIIToUTF16("Handler")); |
| 270 content_settings->set_pending_protocol_handler(test_handler); |
| 271 |
| 272 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 273 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 274 NULL, tab_contents(), profile(), |
| 275 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS)); |
| 276 |
| 277 { |
| 278 ProtocolHandler handler = |
| 279 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); |
| 280 EXPECT_TRUE(handler.IsEmpty()); |
| 281 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 282 content_settings->pending_protocol_handler_setting()); |
| 283 } |
| 284 |
| 285 // "0" is the "Allow" radio button. |
| 286 content_setting_bubble_model->OnRadioClicked(0); |
| 287 { |
| 288 ProtocolHandler handler = |
| 289 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); |
| 290 ASSERT_FALSE(handler.IsEmpty()); |
| 291 EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title()); |
| 292 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 293 content_settings->pending_protocol_handler_setting()); |
| 294 } |
| 295 |
| 296 // "1" is the "Deny" radio button. |
| 297 content_setting_bubble_model->OnRadioClicked(1); |
| 298 { |
| 299 ProtocolHandler handler = |
| 300 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); |
| 301 EXPECT_TRUE(handler.IsEmpty()); |
| 302 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 303 content_settings->pending_protocol_handler_setting()); |
| 304 } |
| 305 |
| 306 // "2" is the "Ignore button. |
| 307 content_setting_bubble_model->OnRadioClicked(2); |
| 308 { |
| 309 ProtocolHandler handler = |
| 310 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); |
| 311 EXPECT_TRUE(handler.IsEmpty()); |
| 312 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
| 313 content_settings->pending_protocol_handler_setting()); |
| 314 EXPECT_TRUE(profile()->GetProtocolHandlerRegistry()->IsIgnored( |
| 315 test_handler)); |
| 316 } |
| 317 |
| 318 // "0" is the "Allow" radio button. |
| 319 content_setting_bubble_model->OnRadioClicked(0); |
| 320 { |
| 321 ProtocolHandler handler = |
| 322 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); |
| 323 ASSERT_FALSE(handler.IsEmpty()); |
| 324 EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title()); |
| 325 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 326 content_settings->pending_protocol_handler_setting()); |
| 327 EXPECT_FALSE(profile()->GetProtocolHandlerRegistry()->IsIgnored( |
| 328 test_handler)); |
| 329 } |
| 330 } |
| OLD | NEW |