Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/ui/views/location_bar/content_setting_bubble_dialog_browsertest.cc

Issue 2668833003: DialogBrowserTest implementation to invoke Content settings bubble dialogs. (Closed)
Patch Set: Removed the 'deceptive content' enum element in favor of the new 'subresource filter' element Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 class ContentSettingBubbleDialogTest : public DialogBrowserTest {
25 public:
26 ContentSettingBubbleDialogTest() {}
27
28 void ShowDialogBubble(ContentSettingsType content_type);
29
30 void ShowDialog(const std::string& name) override;
31
32 private:
33 DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleDialogTest);
34 };
35
36 void ContentSettingBubbleDialogTest::ShowDialogBubble(
37 ContentSettingsType content_type) {
38 content::WebContents* web_contents =
39 browser()->tab_strip_model()->GetActiveWebContents();
40 TabSpecificContentSettings* content_settings =
41 TabSpecificContentSettings::FromWebContents(web_contents);
42 switch (content_type) {
43 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
44 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
45 content_settings->OnMediaStreamPermissionSet(
46 GURL::EmptyGURL(),
47 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC
48 ? TabSpecificContentSettings::MICROPHONE_ACCESSED
49 : TabSpecificContentSettings::CAMERA_ACCESSED,
50 std::string(), std::string(), std::string(), std::string());
51 break;
52 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
53 content_settings->OnGeolocationPermissionSet(GURL::EmptyGURL(), false);
54 break;
55 default:
56 // For all other content_types passed in, mark them as blocked.
57 content_settings->OnContentBlocked(content_type);
58 break;
59 }
60 browser()->window()->UpdateToolbar(web_contents);
61 LocationBarTesting* location_bar_testing =
62 browser()->window()->GetLocationBar()->GetLocationBarForTesting();
63 EXPECT_TRUE(location_bar_testing->TestContentSettingImagePressed(
64 ContentSettingImageModel::GetContentSettingImageModelIndexForTesting(
65 content_type)));
66 }
67
68 void ContentSettingBubbleDialogTest::ShowDialog(const std::string& name) {
69 constexpr struct {
70 const char* name;
71 ContentSettingsType content_type;
72 } content_settings_values[] = {
73 {"cookies", CONTENT_SETTINGS_TYPE_COOKIES},
74 {"images", CONTENT_SETTINGS_TYPE_IMAGES},
75 {"javascript", CONTENT_SETTINGS_TYPE_JAVASCRIPT},
76 {"plugins", CONTENT_SETTINGS_TYPE_PLUGINS},
77 {"popups", CONTENT_SETTINGS_TYPE_POPUPS},
78 {"geolocation", CONTENT_SETTINGS_TYPE_GEOLOCATION},
79 {"ppapi_broker", CONTENT_SETTINGS_TYPE_PPAPI_BROKER},
80 {"mixed_script", CONTENT_SETTINGS_TYPE_MIXEDSCRIPT},
81 {"mediastream_mic", CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC},
82 {"mediastream_camera", CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA},
83 {"protocol_handlers", CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS},
84 {"automatic_downloads", CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS},
85 {"midi_sysex", CONTENT_SETTINGS_TYPE_MIDI_SYSEX},
86 {"subresource_filter", CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER}};
87 for (auto content_settings : content_settings_values) {
88 if (name == content_settings.name) {
89 ShowDialogBubble(content_settings.content_type);
90 return;
91 }
92 }
93 ADD_FAILURE() << "Unknown dialog type";
94 }
95
96 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_cookies) {
97 RunDialog();
98 }
99
100 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_images) {
101 RunDialog();
102 }
103
104 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
105 InvokeDialog_javascript) {
106 RunDialog();
107 }
108
109 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_plugins) {
110 RunDialog();
111 }
112
113 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_popups) {
114 RunDialog();
115 }
116
117 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
118 InvokeDialog_geolocation) {
119 RunDialog();
120 }
121
122 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
123 InvokeDialog_ppapi_broker) {
124 RunDialog();
125 }
126
127 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
128 InvokeDialog_mixed_script) {
129 RunDialog();
130 }
131
132 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
133 InvokeDialog_mediastream_mic) {
134 RunDialog();
135 }
136
137 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
138 InvokeDialog_mediastream_camera) {
139 RunDialog();
140 }
141
142 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
143 InvokeDialog_protocol_handlers) {
144 RunDialog();
145 }
146
147 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
148 InvokeDialog_automatic_downloads) {
149 RunDialog();
150 }
151
152 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
153 InvokeDialog_midi_sysex) {
154 RunDialog();
155 }
156
157 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
158 InvokeDialog_subresource_filter) {
159 RunDialog();
160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698