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

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: Temporarily added --disable-gpu when launching subprocess. Filled out all bubble dialog invocation … 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/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"
16 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
17 #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h"
18 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "components/content_settings/core/common/content_settings_types.h"
21 #include "ui/events/event.h"
22 #include "ui/events/event_constants.h"
23 #include "ui/views/view.h"
24 #include "ui/views/widget/widget.h"
25 #include "url/gurl.h"
26
27 class ContentSettingBubbleDialogTest : public DialogBrowserTest {
28 public:
29 ContentSettingBubbleDialogTest() {}
30
31 ContentSettingImageModel* GetImageModel(ContentSettingsType content_type,
32 LocationBarTesting* location_bar) {
33 for (int i = 0; i < location_bar->ContentSettingImageModelCount(); i++) {
34 ContentSettingImageModel* image_model =
35 location_bar->GetContentSettingImageModel(i);
36 if (image_model->content_type() == content_type)
37 return image_model;
38 }
39 return nullptr;
40 }
41
42 void ShowDialogBubble(ContentSettingsType content_type) {
43 content::WebContents* web_contents =
44 browser()->tab_strip_model()->GetActiveWebContents();
45 TabSpecificContentSettings* content_settings =
46 TabSpecificContentSettings::FromWebContents(web_contents);
47 switch (content_type) {
48 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
49 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
50 content_settings->OnMediaStreamPermissionSet(
51 GURL::EmptyGURL(),
52 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC
53 ? TabSpecificContentSettings::MICROPHONE_ACCESSED
54 : TabSpecificContentSettings::CAMERA_ACCESSED,
55 std::string(), std::string(), std::string(), std::string());
56 break;
57 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
58 content_settings->OnGeolocationPermissionSet(
59 GURL::EmptyGURL(), false);
60 break;
61 default:
62 content_settings->OnContentBlocked(content_type);
63 }
64 BrowserView* browser_view =
65 BrowserView::GetBrowserViewForBrowser(browser());
66 LocationBarView* location_bar_view = browser_view->GetLocationBarView();
67 LocationBar* location_bar = location_bar_view;
68 LocationBarTesting* location_bar_testing =
69 location_bar->GetLocationBarForTesting();
70 location_bar_view->Update(web_contents);
71 ContentSettingImageModel* image_model =
72 GetImageModel(content_type, location_bar_testing);
73 EXPECT_NE(image_model, nullptr);
74 ContentSettingImageView* image_view =
75 location_bar_view->GetContentSettingImageViewFromImageModel(
76 image_model);
77 EXPECT_NE(image_view, nullptr);
78 image_view->OnActivate(ui::MouseEvent(
79 ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), gfx::Point(0, 0),
80 base::TimeTicks::Now(), ui::EF_LEFT_MOUSE_BUTTON, 0));
81 EXPECT_NE(image_view->bubble_view(), nullptr);
82 EXPECT_TRUE(image_view->bubble_view()->visible());
83 views::Widget* widget = image_view->bubble_view()->GetWidget();
84 EXPECT_TRUE(widget->IsVisible());
85 }
86
87 void ShowDialog(const std::string& name) override {
88 const struct _content_settings_values {
89 std::string name;
90 ContentSettingsType content_type;
91 } content_settings_values[] = {
92 {std::string("cookies"), CONTENT_SETTINGS_TYPE_COOKIES},
93 {std::string("images"), CONTENT_SETTINGS_TYPE_IMAGES},
94 {std::string("javascript"), CONTENT_SETTINGS_TYPE_JAVASCRIPT},
95 {std::string("plugins"), CONTENT_SETTINGS_TYPE_PLUGINS},
96 {std::string("popups"), CONTENT_SETTINGS_TYPE_POPUPS},
97 {std::string("geolocation"), CONTENT_SETTINGS_TYPE_GEOLOCATION},
98 {std::string("ppapi_broker"), CONTENT_SETTINGS_TYPE_PPAPI_BROKER},
99 {std::string("mixed_script"), CONTENT_SETTINGS_TYPE_MIXEDSCRIPT},
100 {std::string("mediastream_mic"), CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC},
101 {std::string("mediastream_camera"),
102 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA},
103 {std::string("protocol_handlers"),
104 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS},
105 {std::string("automatic_downloads"),
106 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS},
107 {std::string("midi_sysex"), CONTENT_SETTINGS_TYPE_MIDI_SYSEX},
108 };
109 for (size_t i = 0; i < sizeof(content_settings_values) /
110 sizeof(content_settings_values[0]);
111 ++i) {
112 if (name == content_settings_values[i].name) {
113 ShowDialogBubble(content_settings_values[i].content_type);
114 return;
115 }
116 }
117 EXPECT_TRUE(false);
118 }
119 };
120
121 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_cookies) {
122 RunDialog();
123 }
124
125 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_images) {
126 RunDialog();
127 }
128
129 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
130 InvokeDialog_javascript) {
131 RunDialog();
132 }
133
134 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_plugins) {
135 RunDialog();
136 }
137
138 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest, InvokeDialog_popups) {
139 RunDialog();
140 }
141
142 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
143 InvokeDialog_geolocation) {
144 RunDialog();
145 }
146
147 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
148 InvokeDialog_ppapi_broker) {
149 RunDialog();
150 }
151
152 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
153 InvokeDialog_mixed_script) {
154 RunDialog();
155 }
156
157 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
158 InvokeDialog_mediastream_mic) {
159 RunDialog();
160 }
161
162 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
163 InvokeDialog_mediastream_camera) {
164 RunDialog();
165 }
166
167 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
168 InvokeDialog_protocol_handlers) {
169 RunDialog();
170 }
171
172 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
173 InvokeDialog_automatic_downloads) {
174 RunDialog();
175 }
176
177 IN_PROC_BROWSER_TEST_F(ContentSettingBubbleDialogTest,
178 InvokeDialog_midi_sysex) {
179 RunDialog();
180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698