Chromium Code Reviews| 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->SetPendingProtocolHandler( | |
| 233 ProtocolHandler::CreateProtocolHandler( | |
| 234 "mailto", GURL("http://www.toplevel.example/"), | |
|
Peter Kasting
2012/06/25 23:55:30
Nit: If you're going to combine args on the same l
Greg Billock
2012/06/26 19:17:04
Done, but it doesn't always fit. :-(
| |
| 235 ASCIIToUTF16("Handler"))); | |
| 236 | |
| 237 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | |
| 238 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | |
| 239 NULL, tab_contents(), profile(), | |
| 240 CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER)); | |
| 241 const ContentSettingBubbleModel::BubbleContent& bubble_content = | |
| 242 content_setting_bubble_model->bubble_content(); | |
| 243 EXPECT_FALSE(bubble_content.title.empty()); | |
| 244 EXPECT_FALSE(bubble_content.radio_group.radio_items.empty()); | |
| 245 EXPECT_TRUE(bubble_content.popup_items.empty()); | |
| 246 EXPECT_EQ(0U, bubble_content.domain_lists.size()); | |
|
Peter Kasting
2012/06/25 23:55:30
Nit: Why not _TRUE(...empty()) here too?
Bernhard Bauer
2012/06/26 09:08:34
An advantage of this version is that the error mes
Peter Kasting
2012/06/26 17:18:22
I know, but several other things here (radio_items
Greg Billock
2012/06/26 19:17:04
Done.
| |
| 247 EXPECT_TRUE(bubble_content.custom_link.empty()); | |
| 248 EXPECT_FALSE(bubble_content.custom_link_enabled); | |
| 249 EXPECT_FALSE(bubble_content.manage_link.empty()); | |
| 250 } | |
| 251 | |
| 252 TEST_F(ContentSettingBubbleModelTest, RPHAllow) { | |
| 253 profile()->CreateProtocolHandlerRegistry(); | |
| 254 | |
| 255 const GURL page_url("http://toplevel.example/"); | |
| 256 NavigateAndCommit(page_url); | |
| 257 TabSpecificContentSettings* content_settings = | |
| 258 tab_contents()->content_settings(); | |
| 259 ProtocolHandler test_handler = ProtocolHandler::CreateProtocolHandler( | |
| 260 "mailto", GURL("http://www.toplevel.example/"), | |
| 261 ASCIIToUTF16("Handler")); | |
| 262 content_settings->SetPendingProtocolHandler(test_handler); | |
| 263 | |
| 264 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | |
| 265 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | |
| 266 NULL, tab_contents(), profile(), | |
| 267 CONTENT_SETTINGS_TYPE_REGISTER_PROTOCOL_HANDLER)); | |
| 268 | |
| 269 { | |
| 270 ProtocolHandler handler = | |
| 271 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); | |
| 272 EXPECT_TRUE(handler.IsEmpty()); | |
| 273 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | |
| 274 content_settings->GetPendingProtocolHandlerSetting()); | |
| 275 } | |
| 276 | |
| 277 // "0" is the "Allow" radio button. | |
| 278 content_setting_bubble_model->OnRadioClicked(0); | |
|
Bernhard Bauer
2012/06/25 16:52:20
You could move these into constants.
Greg Billock
2012/06/26 19:17:04
Yes. I'd have to promote them out of the CC file,
| |
| 279 { | |
| 280 ProtocolHandler handler = | |
| 281 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); | |
| 282 ASSERT_FALSE(handler.IsEmpty()); | |
| 283 EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title()); | |
| 284 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 285 content_settings->GetPendingProtocolHandlerSetting()); | |
| 286 } | |
| 287 | |
| 288 // "1" is the "Deny" radio button. | |
| 289 content_setting_bubble_model->OnRadioClicked(1); | |
| 290 { | |
| 291 ProtocolHandler handler = | |
| 292 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); | |
| 293 EXPECT_TRUE(handler.IsEmpty()); | |
| 294 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 295 content_settings->GetPendingProtocolHandlerSetting()); | |
| 296 } | |
| 297 | |
| 298 // "2" is the "Ignore button. | |
| 299 content_setting_bubble_model->OnRadioClicked(2); | |
| 300 { | |
| 301 ProtocolHandler handler = | |
| 302 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); | |
| 303 EXPECT_TRUE(handler.IsEmpty()); | |
| 304 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | |
| 305 content_settings->GetPendingProtocolHandlerSetting()); | |
| 306 EXPECT_TRUE(profile()->GetProtocolHandlerRegistry()->IsIgnored( | |
| 307 test_handler)); | |
| 308 } | |
| 309 | |
| 310 // "0" is the "Allow" radio button. | |
| 311 content_setting_bubble_model->OnRadioClicked(0); | |
| 312 { | |
| 313 ProtocolHandler handler = | |
| 314 profile()->GetProtocolHandlerRegistry()->GetHandlerFor("mailto"); | |
| 315 ASSERT_FALSE(handler.IsEmpty()); | |
| 316 EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title()); | |
| 317 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 318 content_settings->GetPendingProtocolHandlerSetting()); | |
| 319 EXPECT_FALSE(profile()->GetProtocolHandlerRegistry()->IsIgnored( | |
| 320 test_handler)); | |
| 321 } | |
| 322 } | |
| OLD | NEW |