OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/memory/ptr_util.h" |
| 6 #include "base/time/time.h" |
| 7 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
| 12 #include "chrome/browser/ui/location_bar/location_bar.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/browser/ui/test/test_browser_dialog.h" |
| 15 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" |
| 16 #include "chrome/test/base/in_process_browser_test.h" |
| 17 #include "components/content_settings/core/common/content_settings_types.h" |
| 18 #include "ui/events/event.h" |
| 19 #include "ui/events/event_constants.h" |
| 20 #include "ui/views/view.h" |
| 21 #include "ui/views/widget/widget.h" |
| 22 #include "url/gurl.h" |
| 23 |
| 24 namespace { |
| 25 |
| 26 int IndexForContentType(ContentSettingsType content_type) { |
| 27 // See ContentSettingImageModel::GenerateContentSettingImageModels(). |
| 28 constexpr ContentSettingsType icon_order[] = { |
| 29 CONTENT_SETTINGS_TYPE_COOKIES, |
| 30 CONTENT_SETTINGS_TYPE_IMAGES, |
| 31 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 32 CONTENT_SETTINGS_TYPE_PPAPI_BROKER, |
| 33 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 34 CONTENT_SETTINGS_TYPE_POPUPS, |
| 35 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 36 CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, |
| 37 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, |
| 38 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, // Media. Shared with Camera. |
| 39 CONTENT_SETTINGS_TYPE_DEFAULT, // Deceptive content (no content type). |
| 40 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| 41 CONTENT_SETTINGS_TYPE_MIDI_SYSEX}; |
| 42 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
| 43 content_type = CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC; |
| 44 |
| 45 for (size_t index = 0; index < arraysize(icon_order); ++index) { |
| 46 if (content_type == icon_order[index]) |
| 47 return index; |
| 48 } |
| 49 |
| 50 return -1; |
| 51 } |
| 52 |
| 53 } // namespace |
| 54 |
| 55 class ContentSettingBubbleDialogTest : public DialogBrowserTest { |
| 56 public: |
| 57 ContentSettingBubbleDialogTest() {} |
| 58 |
| 59 void ShowDialogBubble(ContentSettingsType content_type); |
| 60 void ShowDialog(const std::string& name) override; |
| 61 |
| 62 private: |
| 63 DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleDialogTest); |
| 64 }; |
| 65 |
| 66 void ContentSettingBubbleDialogTest::ShowDialogBubble( |
| 67 ContentSettingsType content_type) { |
| 68 content::WebContents* web_contents = |
| 69 browser()->tab_strip_model()->GetActiveWebContents(); |
| 70 TabSpecificContentSettings* content_settings = |
| 71 TabSpecificContentSettings::FromWebContents(web_contents); |
| 72 |
| 73 switch (content_type) { |
| 74 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: |
| 75 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: |
| 76 content_settings->OnMediaStreamPermissionSet( |
| 77 GURL::EmptyGURL(), |
| 78 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC |
| 79 ? TabSpecificContentSettings::MICROPHONE_ACCESSED |
| 80 : TabSpecificContentSettings::CAMERA_ACCESSED, |
| 81 std::string(), std::string(), std::string(), std::string()); |
| 82 break; |
| 83 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 84 content_settings->OnGeolocationPermissionSet(GURL::EmptyGURL(), false); |
| 85 break; |
| 86 default: |
| 87 // For all other content_types passed in, mark them as blocked. |
| 88 content_settings->OnContentBlocked(content_type); |
| 89 } |
| 90 browser()->window()->UpdateToolbar(web_contents); |
| 91 LocationBarTesting* location_bar_testing = |
| 92 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); |
| 93 EXPECT_TRUE(location_bar_testing->TestContentSettingImagePressed( |
| 94 IndexForContentType(content_type))); |
| 95 } |
| 96 |
| 97 void ContentSettingBubbleDialogTest::ShowDialog(const std::string& name) { |
| 98 const struct { |
| 99 std::string name; |
| 100 ContentSettingsType content_type; |
| 101 } content_settings_values[] = { |
| 102 {std::string("cookies"), CONTENT_SETTINGS_TYPE_COOKIES}, |
| 103 {std::string("images"), CONTENT_SETTINGS_TYPE_IMAGES}, |
| 104 {std::string("javascript"), CONTENT_SETTINGS_TYPE_JAVASCRIPT}, |
| 105 {std::string("plugins"), CONTENT_SETTINGS_TYPE_PLUGINS}, |
| 106 {std::string("popups"), CONTENT_SETTINGS_TYPE_POPUPS}, |
| 107 {std::string("geolocation"), CONTENT_SETTINGS_TYPE_GEOLOCATION}, |
| 108 {std::string("ppapi_broker"), CONTENT_SETTINGS_TYPE_PPAPI_BROKER}, |
| 109 {std::string("mixed_script"), CONTENT_SETTINGS_TYPE_MIXEDSCRIPT}, |
| 110 {std::string("mediastream_mic"), CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC}, |
| 111 {std::string("mediastream_camera"), |
| 112 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA}, |
| 113 {std::string("protocol_handlers"), |
| 114 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS}, |
| 115 {std::string("automatic_downloads"), |
| 116 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS}, |
| 117 {std::string("midi_sysex"), CONTENT_SETTINGS_TYPE_MIDI_SYSEX}, |
| 118 }; |
| 119 for (auto content_settings : content_settings_values) { |
| 120 if (name == content_settings.name) { |
| 121 ShowDialogBubble(content_settings.content_type); |
| 122 return; |
| 123 } |
| 124 } |
| 125 NOTREACHED(); |
| 126 } |
| 127 |
| 128 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_cookies) { |
| 129 RunDialog(); |
| 130 } |
| 131 |
| 132 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_images) { |
| 133 RunDialog(); |
| 134 } |
| 135 |
| 136 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, |
| 137 InvokeDialog_javascript) { |
| 138 RunDialog(); |
| 139 } |
| 140 |
| 141 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_plugins) { |
| 142 RunDialog(); |
| 143 } |
| 144 |
| 145 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_popups) { |
| 146 RunDialog(); |
| 147 } |
| 148 |
| 149 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, |
| 150 InvokeDialog_geolocation) { |
| 151 RunDialog(); |
| 152 } |
| 153 |
| 154 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, |
| 155 InvokeDialog_ppapi_broker) { |
| 156 RunDialog(); |
| 157 } |
| 158 |
| 159 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, |
| 160 InvokeDialog_mixed_script) { |
| 161 RunDialog(); |
| 162 } |
| 163 |
| 164 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, |
| 165 InvokeDialog_mediastream_mic) { |
| 166 RunDialog(); |
| 167 } |
| 168 |
| 169 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, |
| 170 InvokeDialog_mediastream_camera) { |
| 171 RunDialog(); |
| 172 } |
| 173 |
| 174 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, |
| 175 InvokeDialog_protocol_handlers) { |
| 176 RunDialog(); |
| 177 } |
| 178 |
| 179 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, |
| 180 InvokeDialog_automatic_downloads) { |
| 181 RunDialog(); |
| 182 } |
| 183 |
| 184 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, |
| 185 InvokeDialog_midi_sysex) { |
| 186 RunDialog(); |
| 187 } |
OLD | NEW |