Chromium Code Reviews| 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/content_settings/content_setting_image_model.h" | |
| 11 #include "chrome/browser/ui/location_bar/location_bar.h" | |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 13 #include "chrome/browser/ui/test/test_browser_dialog.h" | |
| 14 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" | |
| 15 #include "chrome/browser/ui/views/frame/browser_view.h" | |
|
tapted
2017/02/07 01:23:31
is it possible to drop this? (it isn't linked on M
kylix_rd
2017/02/07 18:25:21
Done.
| |
| 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 class ContentSettingBubbleDialogTest : public DialogBrowserTest { | |
| 25 public: | |
| 26 ContentSettingBubbleDialogTest() {} | |
| 27 | |
| 28 void ShowDialogBubble(ContentSettingsType content_type); | |
| 29 void ShowDialog(const std::string& name) override; | |
| 30 private: | |
|
tapted
2017/02/07 01:23:31
nit: blank line before
kylix_rd
2017/02/07 18:25:21
Done.
| |
| 31 DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleDialogTest); | |
| 32 }; | |
| 33 | |
| 34 void ContentSettingBubbleDialogTest::ShowDialogBubble( | |
| 35 ContentSettingsType content_type) { | |
| 36 content::WebContents* web_contents = | |
| 37 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 38 TabSpecificContentSettings* content_settings = | |
| 39 TabSpecificContentSettings::FromWebContents(web_contents); | |
| 40 switch (content_type) { | |
| 41 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC: | |
| 42 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA: | |
| 43 content_settings->OnMediaStreamPermissionSet( | |
| 44 GURL::EmptyGURL(), | |
| 45 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC | |
| 46 ? TabSpecificContentSettings::MICROPHONE_ACCESSED | |
| 47 : TabSpecificContentSettings::CAMERA_ACCESSED, | |
| 48 std::string(), std::string(), std::string(), std::string()); | |
| 49 break; | |
| 50 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | |
| 51 content_settings->OnGeolocationPermissionSet(GURL::EmptyGURL(), false); | |
| 52 break; | |
| 53 default: | |
| 54 // For all other content_types passed in, mark them as blocked. | |
| 55 content_settings->OnContentBlocked(content_type); | |
| 56 break; | |
| 57 } | |
| 58 browser()->window()->UpdateToolbar(web_contents); | |
| 59 LocationBarTesting* location_bar_testing = | |
| 60 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); | |
| 61 EXPECT_TRUE(location_bar_testing->TestContentSettingImagePressed( | |
| 62 ContentSettingImageModel::GetContentSettingImageModelIndexForTesting( | |
| 63 content_type))); | |
| 64 } | |
| 65 | |
| 66 void ContentSettingBubbleDialogTest::ShowDialog(const std::string& name) { | |
| 67 static constexpr struct { | |
|
tapted
2017/02/07 01:23:31
nit: no need for static (I think that will reserve
| |
| 68 const char* name; | |
| 69 ContentSettingsType content_type; | |
| 70 } content_settings_values[] = { | |
| 71 {"cookies", CONTENT_SETTINGS_TYPE_COOKIES}, | |
| 72 {"images", CONTENT_SETTINGS_TYPE_IMAGES}, | |
| 73 {"javascript", CONTENT_SETTINGS_TYPE_JAVASCRIPT}, | |
| 74 {"plugins", CONTENT_SETTINGS_TYPE_PLUGINS}, | |
| 75 {"popups", CONTENT_SETTINGS_TYPE_POPUPS}, | |
| 76 {"geolocation", CONTENT_SETTINGS_TYPE_GEOLOCATION}, | |
| 77 {"ppapi_broker", CONTENT_SETTINGS_TYPE_PPAPI_BROKER}, | |
| 78 {"mixed_script", CONTENT_SETTINGS_TYPE_MIXEDSCRIPT}, | |
| 79 {"mediastream_mic", CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC}, | |
| 80 {"mediastream_camera", CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA}, | |
| 81 {"protocol_handlers", CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS}, | |
| 82 {"automatic_downloads", CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS}, | |
| 83 {"midi_sysex", CONTENT_SETTINGS_TYPE_MIDI_SYSEX}, | |
| 84 }; | |
| 85 for (auto content_settings : content_settings_values) { | |
| 86 if (name == content_settings.name) { | |
| 87 ShowDialogBubble(content_settings.content_type); | |
| 88 return; | |
| 89 } | |
| 90 } | |
| 91 ADD_FAILURE(); | |
|
tapted
2017/02/07 01:23:31
nit: maybe comment here like " // Not reached."? I
| |
| 92 } | |
| 93 | |
| 94 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_cookies) { | |
| 95 RunDialog(); | |
| 96 } | |
| 97 | |
| 98 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_images) { | |
| 99 RunDialog(); | |
| 100 } | |
| 101 | |
| 102 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, | |
| 103 InvokeDialog_javascript) { | |
| 104 RunDialog(); | |
| 105 } | |
| 106 | |
| 107 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_plugins) { | |
| 108 RunDialog(); | |
| 109 } | |
| 110 | |
| 111 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_popups) { | |
| 112 RunDialog(); | |
| 113 } | |
| 114 | |
| 115 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, | |
| 116 InvokeDialog_geolocation) { | |
| 117 RunDialog(); | |
| 118 } | |
| 119 | |
| 120 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, | |
| 121 InvokeDialog_ppapi_broker) { | |
| 122 RunDialog(); | |
| 123 } | |
| 124 | |
| 125 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, | |
| 126 InvokeDialog_mixed_script) { | |
| 127 RunDialog(); | |
| 128 } | |
| 129 | |
| 130 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, | |
| 131 InvokeDialog_mediastream_mic) { | |
| 132 RunDialog(); | |
| 133 } | |
| 134 | |
| 135 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, | |
| 136 InvokeDialog_mediastream_camera) { | |
| 137 RunDialog(); | |
| 138 } | |
| 139 | |
| 140 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, | |
| 141 InvokeDialog_protocol_handlers) { | |
| 142 RunDialog(); | |
| 143 } | |
| 144 | |
| 145 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, | |
| 146 InvokeDialog_automatic_downloads) { | |
| 147 RunDialog(); | |
| 148 } | |
| 149 | |
| 150 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, | |
| 151 InvokeDialog_midi_sysex) { | |
| 152 RunDialog(); | |
| 153 } | |
| OLD | NEW |