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

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

Powered by Google App Engine
This is Rietveld 408576698