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

Side by Side Diff: chrome/browser/ui/website_settings/permission_bubble_manager_browsertest.cc

Issue 2081103002: Rename PermissionBubbleManager to PermissionRequestManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 4 years, 5 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 2015 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 "chrome/browser/ui/website_settings/permission_bubble_manager.h"
6
7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h"
9 #include "build/build_config.h"
10 #include "chrome/browser/permissions/permission_context_base.h"
11 #include "chrome/browser/permissions/permission_util.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/browser/ui/website_settings/mock_permission_bubble_factory.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/ui_test_utils.h"
17 #include "components/variations/variations_associated_data.h"
18 #include "content/public/browser/permission_type.h"
19 #include "content/public/test/browser_test_utils.h"
20 #include "content/public/test/test_utils.h"
21 #include "net/test/embedded_test_server/embedded_test_server.h"
22
23 namespace {
24
25 const char* kPermissionsKillSwitchFieldStudy =
26 PermissionContextBase::kPermissionsKillSwitchFieldStudy;
27 const char* kPermissionsKillSwitchBlockedValue =
28 PermissionContextBase::kPermissionsKillSwitchBlockedValue;
29 const char kPermissionsKillSwitchTestGroup[] = "TestGroup";
30
31 class PermissionBubbleManagerBrowserTest : public InProcessBrowserTest {
32 public:
33 PermissionBubbleManagerBrowserTest() = default;
34 ~PermissionBubbleManagerBrowserTest() override = default;
35
36 void SetUpOnMainThread() override {
37 InProcessBrowserTest::SetUpOnMainThread();
38 PermissionBubbleManager* manager = GetPermissionBubbleManager();
39 mock_permission_bubble_factory_.reset(
40 new MockPermissionBubbleFactory(manager));
41 manager->DisplayPendingRequests();
42 }
43
44 void TearDownOnMainThread() override {
45 mock_permission_bubble_factory_.reset();
46 InProcessBrowserTest::TearDownOnMainThread();
47 }
48
49 PermissionBubbleManager* GetPermissionBubbleManager() {
50 return PermissionBubbleManager::FromWebContents(
51 browser()->tab_strip_model()->GetActiveWebContents());
52 }
53
54 MockPermissionBubbleFactory* bubble_factory() {
55 return mock_permission_bubble_factory_.get();
56 }
57
58 void EnableKillSwitch(content::PermissionType permission_type) {
59 std::map<std::string, std::string> params;
60 params[PermissionUtil::GetPermissionString(permission_type)] =
61 kPermissionsKillSwitchBlockedValue;
62 variations::AssociateVariationParams(
63 kPermissionsKillSwitchFieldStudy, kPermissionsKillSwitchTestGroup,
64 params);
65 base::FieldTrialList::CreateFieldTrial(kPermissionsKillSwitchFieldStudy,
66 kPermissionsKillSwitchTestGroup);
67 }
68
69 private:
70 std::unique_ptr<MockPermissionBubbleFactory> mock_permission_bubble_factory_;
71 };
72
73 // Requests before the load event should be bundled into one bubble.
74 // http://crbug.com/512849 flaky
75 IN_PROC_BROWSER_TEST_F(PermissionBubbleManagerBrowserTest,
76 DISABLED_RequestsBeforeLoad) {
77 ASSERT_TRUE(embedded_test_server()->Start());
78
79 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
80 browser(),
81 embedded_test_server()->GetURL("/permissions/requests-before-load.html"),
82 1);
83 bubble_factory()->WaitForPermissionBubble();
84
85 EXPECT_EQ(1, bubble_factory()->show_count());
86 EXPECT_EQ(2, bubble_factory()->total_request_count());
87 }
88
89 // Requests before the load should not be bundled with a request after the load.
90 IN_PROC_BROWSER_TEST_F(PermissionBubbleManagerBrowserTest,
91 RequestsBeforeAfterLoad) {
92 ASSERT_TRUE(embedded_test_server()->Start());
93
94 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
95 browser(),
96 embedded_test_server()->GetURL(
97 "/permissions/requests-before-after-load.html"),
98 1);
99 bubble_factory()->WaitForPermissionBubble();
100
101 EXPECT_EQ(1, bubble_factory()->show_count());
102 EXPECT_EQ(1, bubble_factory()->total_request_count());
103 }
104
105 // Navigating twice to the same URL should be equivalent to refresh. This means
106 // showing the bubbles twice.
107 // http://crbug.com/512849 flaky
108 #if defined(OS_WIN)
109 #define MAYBE_NavTwice DISABLED_NavTwice
110 #else
111 #define MAYBE_NavTwice NavTwice
112 #endif
113 IN_PROC_BROWSER_TEST_F(PermissionBubbleManagerBrowserTest, MAYBE_NavTwice) {
114 ASSERT_TRUE(embedded_test_server()->Start());
115
116 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
117 browser(),
118 embedded_test_server()->GetURL("/permissions/requests-before-load.html"),
119 1);
120 bubble_factory()->WaitForPermissionBubble();
121
122 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
123 browser(),
124 embedded_test_server()->GetURL("/permissions/requests-before-load.html"),
125 1);
126 bubble_factory()->WaitForPermissionBubble();
127
128 EXPECT_EQ(2, bubble_factory()->show_count());
129 EXPECT_EQ(4, bubble_factory()->total_request_count());
130 }
131
132 // Navigating twice to the same URL with a hash should be navigation within the
133 // page. This means the bubble is only shown once.
134 // http://crbug.com/512849 flaky
135 #if defined(OS_WIN)
136 #define MAYBE_NavTwiceWithHash DISABLED_NavTwiceWithHash
137 #else
138 #define MAYBE_NavTwiceWithHash NavTwiceWithHash
139 #endif
140 IN_PROC_BROWSER_TEST_F(PermissionBubbleManagerBrowserTest,
141 MAYBE_NavTwiceWithHash) {
142 ASSERT_TRUE(embedded_test_server()->Start());
143
144 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
145 browser(),
146 embedded_test_server()->GetURL("/permissions/requests-before-load.html"),
147 1);
148 bubble_factory()->WaitForPermissionBubble();
149
150 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
151 browser(),
152 embedded_test_server()->GetURL(
153 "/permissions/requests-before-load.html#0"),
154 1);
155 bubble_factory()->WaitForPermissionBubble();
156
157 EXPECT_EQ(1, bubble_factory()->show_count());
158 EXPECT_EQ(2, bubble_factory()->total_request_count());
159 }
160
161 // Bubble requests should be shown after in-page navigation.
162 IN_PROC_BROWSER_TEST_F(PermissionBubbleManagerBrowserTest, InPageNavigation) {
163 ASSERT_TRUE(embedded_test_server()->Start());
164
165 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
166 browser(),
167 embedded_test_server()->GetURL("/empty.html"),
168 1);
169
170 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
171 browser(),
172 embedded_test_server()->GetURL("/empty.html#0"),
173 1);
174
175 // Request 'geolocation' permission.
176 ExecuteScriptAndGetValue(
177 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(),
178 "navigator.geolocation.getCurrentPosition(function(){});");
179 bubble_factory()->WaitForPermissionBubble();
180
181 EXPECT_EQ(1, bubble_factory()->show_count());
182 EXPECT_EQ(1, bubble_factory()->total_request_count());
183 }
184
185 // Bubble requests should not be shown when the killswitch is on.
186 IN_PROC_BROWSER_TEST_F(PermissionBubbleManagerBrowserTest,
187 KillSwitchGeolocation) {
188 ASSERT_TRUE(embedded_test_server()->Start());
189
190 ui_test_utils::NavigateToURL(
191 browser(),
192 embedded_test_server()->GetURL("/permissions/killswitch_tester.html"));
193
194 // Now enable the geolocation killswitch.
195 EnableKillSwitch(content::PermissionType::GEOLOCATION);
196 content::WebContents* web_contents =
197 browser()->tab_strip_model()->GetActiveWebContents();
198
199 std::string result;
200 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
201 web_contents, "requestGeolocation();", &result));
202 EXPECT_EQ("denied", result);
203 EXPECT_EQ(0, bubble_factory()->show_count());
204 EXPECT_EQ(0, bubble_factory()->total_request_count());
205
206 // Disable the trial.
207 variations::testing::ClearAllVariationParams();
208
209 // Reload the page to get around blink layer caching for geolocation
210 // requests.
211 ui_test_utils::NavigateToURL(
212 browser(),
213 embedded_test_server()->GetURL("/permissions/killswitch_tester.html"));
214
215 EXPECT_TRUE(content::ExecuteScript(web_contents, "requestGeolocation();"));
216 bubble_factory()->WaitForPermissionBubble();
217 EXPECT_EQ(1, bubble_factory()->show_count());
218 EXPECT_EQ(1, bubble_factory()->total_request_count());
219 }
220
221 // Bubble requests should not be shown when the killswitch is on.
222 IN_PROC_BROWSER_TEST_F(PermissionBubbleManagerBrowserTest,
223 KillSwitchNotifications) {
224 ASSERT_TRUE(embedded_test_server()->Start());
225
226 ui_test_utils::NavigateToURL(
227 browser(),
228 embedded_test_server()->GetURL("/permissions/killswitch_tester.html"));
229
230 // Now enable the notifications killswitch.
231 EnableKillSwitch(content::PermissionType::NOTIFICATIONS);
232 content::WebContents* web_contents =
233 browser()->tab_strip_model()->GetActiveWebContents();
234
235 std::string result;
236 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
237 web_contents, "requestNotification();", &result));
238 EXPECT_EQ("denied", result);
239 EXPECT_EQ(0, bubble_factory()->show_count());
240 EXPECT_EQ(0, bubble_factory()->total_request_count());
241
242 // Disable the trial.
243 variations::testing::ClearAllVariationParams();
244
245 EXPECT_TRUE(content::ExecuteScript(web_contents, "requestNotification();"));
246 bubble_factory()->WaitForPermissionBubble();
247 EXPECT_EQ(1, bubble_factory()->show_count());
248 EXPECT_EQ(1, bubble_factory()->total_request_count());
249 }
250
251 } // anonymous namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698