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" |
11 #include "chrome/browser/infobars/infobar_delegate.h" | 11 #include "chrome/browser/infobars/infobar_delegate.h" |
12 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
| 13 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 15 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/content_settings.h" | 17 #include "chrome/common/content_settings.h" |
17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
18 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 #include "content/public/test/test_browser_thread.h" | |
21 #include "content/public/test/web_contents_tester.h" | 21 #include "content/public/test/web_contents_tester.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 using content::BrowserThread; | |
25 using content::WebContentsTester; | 24 using content::WebContentsTester; |
26 | 25 |
27 class ContentSettingBubbleModelTest : public ChromeRenderViewHostTestHarness { | 26 class ContentSettingBubbleModelTest : public ChromeRenderViewHostTestHarness { |
28 protected: | 27 protected: |
29 ContentSettingBubbleModelTest() | |
30 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()) {} | |
31 | |
32 virtual void SetUp() OVERRIDE { | 28 virtual void SetUp() OVERRIDE { |
33 ChromeRenderViewHostTestHarness::SetUp(); | 29 ChromeRenderViewHostTestHarness::SetUp(); |
34 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 30 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
35 InfoBarService::CreateForWebContents(web_contents()); | 31 InfoBarService::CreateForWebContents(web_contents()); |
36 } | 32 } |
37 | 33 |
38 void CheckGeolocationBubble(size_t expected_domains, | 34 void CheckGeolocationBubble(size_t expected_domains, |
39 bool expect_clear_link, | 35 bool expect_clear_link, |
40 bool expect_reload_hint) { | 36 bool expect_reload_hint) { |
41 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 37 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
42 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 38 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
43 NULL, web_contents(), profile(), | 39 NULL, web_contents(), profile(), |
44 CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 40 CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
45 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 41 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
46 content_setting_bubble_model->bubble_content(); | 42 content_setting_bubble_model->bubble_content(); |
47 EXPECT_TRUE(bubble_content.title.empty()); | 43 EXPECT_TRUE(bubble_content.title.empty()); |
48 EXPECT_TRUE(bubble_content.radio_group.radio_items.empty()); | 44 EXPECT_TRUE(bubble_content.radio_group.radio_items.empty()); |
49 EXPECT_TRUE(bubble_content.popup_items.empty()); | 45 EXPECT_TRUE(bubble_content.popup_items.empty()); |
50 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size()); | 46 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size()); |
51 EXPECT_NE(expect_clear_link || expect_reload_hint, | 47 EXPECT_NE(expect_clear_link || expect_reload_hint, |
52 bubble_content.custom_link.empty()); | 48 bubble_content.custom_link.empty()); |
53 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled); | 49 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled); |
54 EXPECT_FALSE(bubble_content.manage_link.empty()); | 50 EXPECT_FALSE(bubble_content.manage_link.empty()); |
55 } | 51 } |
56 | |
57 content::TestBrowserThread ui_thread_; | |
58 }; | 52 }; |
59 | 53 |
60 TEST_F(ContentSettingBubbleModelTest, ImageRadios) { | 54 TEST_F(ContentSettingBubbleModelTest, ImageRadios) { |
61 TabSpecificContentSettings* content_settings = | 55 TabSpecificContentSettings* content_settings = |
62 TabSpecificContentSettings::FromWebContents(web_contents()); | 56 TabSpecificContentSettings::FromWebContents(web_contents()); |
63 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, | 57 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, |
64 std::string()); | 58 std::string()); |
65 | 59 |
66 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 60 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
67 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 61 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 ASSERT_EQ(2U, bubble_content_2.radio_group.radio_items.size()); | 103 ASSERT_EQ(2U, bubble_content_2.radio_group.radio_items.size()); |
110 // TODO(bauerb): Update this once the strings have been updated. | 104 // TODO(bauerb): Update this once the strings have been updated. |
111 EXPECT_EQ(radio1, bubble_content_2.radio_group.radio_items[0]); | 105 EXPECT_EQ(radio1, bubble_content_2.radio_group.radio_items[0]); |
112 EXPECT_EQ(radio2, bubble_content_2.radio_group.radio_items[1]); | 106 EXPECT_EQ(radio2, bubble_content_2.radio_group.radio_items[1]); |
113 EXPECT_FALSE(bubble_content_2.custom_link.empty()); | 107 EXPECT_FALSE(bubble_content_2.custom_link.empty()); |
114 EXPECT_TRUE(bubble_content_2.custom_link_enabled); | 108 EXPECT_TRUE(bubble_content_2.custom_link_enabled); |
115 EXPECT_FALSE(bubble_content_2.manage_link.empty()); | 109 EXPECT_FALSE(bubble_content_2.manage_link.empty()); |
116 } | 110 } |
117 | 111 |
118 TEST_F(ContentSettingBubbleModelTest, Mediastream) { | 112 TEST_F(ContentSettingBubbleModelTest, Mediastream) { |
| 113 // Required to break dependency on BrowserMainLoop. |
| 114 MediaCaptureDevicesDispatcher::GetInstance()-> |
| 115 DisableDeviceEnumerationForTesting(); |
| 116 |
119 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 117 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
120 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 118 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
121 NULL, web_contents(), profile(), | 119 NULL, web_contents(), profile(), |
122 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); | 120 CONTENT_SETTINGS_TYPE_MEDIASTREAM)); |
123 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 121 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
124 content_setting_bubble_model->bubble_content(); | 122 content_setting_bubble_model->bubble_content(); |
125 EXPECT_FALSE(bubble_content.title.empty()); | 123 EXPECT_FALSE(bubble_content.title.empty()); |
126 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); | 124 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); |
127 EXPECT_EQ(0, bubble_content.radio_group.default_item); | 125 EXPECT_EQ(0, bubble_content.radio_group.default_item); |
128 EXPECT_TRUE(bubble_content.custom_link.empty()); | 126 EXPECT_TRUE(bubble_content.custom_link.empty()); |
129 EXPECT_FALSE(bubble_content.custom_link_enabled); | 127 EXPECT_FALSE(bubble_content.custom_link_enabled); |
130 EXPECT_FALSE(bubble_content.manage_link.empty()); | 128 EXPECT_FALSE(bubble_content.manage_link.empty()); |
131 EXPECT_EQ(2U, bubble_content.media_menus.size()); | 129 EXPECT_EQ(2U, bubble_content.media_menus.size()); |
132 } | 130 } |
133 | 131 |
134 TEST_F(ContentSettingBubbleModelTest, BlockedMediastream) { | 132 TEST_F(ContentSettingBubbleModelTest, BlockedMediastream) { |
| 133 // Required to break dependency on BrowserMainLoop. |
| 134 MediaCaptureDevicesDispatcher::GetInstance()-> |
| 135 DisableDeviceEnumerationForTesting(); |
| 136 |
135 WebContentsTester::For(web_contents())-> | 137 WebContentsTester::For(web_contents())-> |
136 NavigateAndCommit(GURL("https://www.example.com")); | 138 NavigateAndCommit(GURL("https://www.example.com")); |
137 GURL url = web_contents()->GetURL(); | 139 GURL url = web_contents()->GetURL(); |
138 | 140 |
139 HostContentSettingsMap* host_content_settings_map = | 141 HostContentSettingsMap* host_content_settings_map = |
140 profile()->GetHostContentSettingsMap(); | 142 profile()->GetHostContentSettingsMap(); |
141 ContentSettingsPattern primary_pattern = | 143 ContentSettingsPattern primary_pattern = |
142 ContentSettingsPattern::FromURL(url); | 144 ContentSettingsPattern::FromURL(url); |
143 ContentSetting setting = CONTENT_SETTING_BLOCK; | 145 ContentSetting setting = CONTENT_SETTING_BLOCK; |
144 host_content_settings_map->SetContentSetting( | 146 host_content_settings_map->SetContentSetting( |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 506 ProtocolHandler handler = registry.GetHandlerFor("mailto"); |
505 ASSERT_FALSE(handler.IsEmpty()); | 507 ASSERT_FALSE(handler.IsEmpty()); |
506 EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title()); | 508 EXPECT_EQ(ASCIIToUTF16("Handler"), handler.title()); |
507 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 509 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
508 content_settings->pending_protocol_handler_setting()); | 510 content_settings->pending_protocol_handler_setting()); |
509 EXPECT_FALSE(registry.IsIgnored(test_handler)); | 511 EXPECT_FALSE(registry.IsIgnored(test_handler)); |
510 } | 512 } |
511 | 513 |
512 registry.Shutdown(); | 514 registry.Shutdown(); |
513 } | 515 } |
OLD | NEW |