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

Side by Side Diff: chrome/browser/permissions/permission_request_manager_browsertest.cc

Issue 2913393002: Only show grouped permission bubbles for mic/camera permissions (Closed)
Patch Set: Remove grouped requests Created 3 years, 6 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/permissions/permission_request_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 "base/test/scoped_feature_list.h" 9 #include "base/test/scoped_feature_list.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 auto decided = [](bool, ContentSetting) {}; 204 auto decided = [](bool, ContentSetting) {};
205 auto cleanup = [] {}; // Leave cleanup to test harness destructor. 205 auto cleanup = [] {}; // Leave cleanup to test harness destructor.
206 owned_requests_.push_back(base::MakeUnique<PermissionRequestImpl>( 206 owned_requests_.push_back(base::MakeUnique<PermissionRequestImpl>(
207 GetUrl(), permission, browser()->profile(), user_gesture, 207 GetUrl(), permission, browser()->profile(), user_gesture,
208 base::Bind(decided), base::Bind(cleanup))); 208 base::Bind(decided), base::Bind(cleanup)));
209 return owned_requests_.back().get(); 209 return owned_requests_.back().get();
210 } 210 }
211 211
212 void PermissionDialogTest::ShowDialog(const std::string& name) { 212 void PermissionDialogTest::ShowDialog(const std::string& name) {
213 constexpr const char* kMultipleName = "multiple"; 213 constexpr const char* kMultipleName = "multiple";
214 // Permissions to request for a "multiple" request. Only types handled in
215 // PermissionRequestImpl::GetMessageTextFragment() are valid.
216 constexpr ContentSettingsType kMultipleRequests[] = {
217 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
218 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
219 };
220 constexpr ContentSettingsType kMultipleRequestsWithMedia[] = {
221 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
222 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
223 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA};
224 constexpr struct { 214 constexpr struct {
225 const char* name; 215 const char* name;
226 ContentSettingsType type; 216 ContentSettingsType type;
227 } kNameToType[] = { 217 } kNameToType[] = {
228 {"flash", CONTENT_SETTINGS_TYPE_PLUGINS}, 218 {"flash", CONTENT_SETTINGS_TYPE_PLUGINS},
229 {"geolocation", CONTENT_SETTINGS_TYPE_GEOLOCATION}, 219 {"geolocation", CONTENT_SETTINGS_TYPE_GEOLOCATION},
230 {"protected_media", CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER}, 220 {"protected_media", CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER},
231 {"notifications", CONTENT_SETTINGS_TYPE_NOTIFICATIONS}, 221 {"notifications", CONTENT_SETTINGS_TYPE_NOTIFICATIONS},
232 {"mic", CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC}, 222 {"mic", CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC},
233 {"camera", CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA}, 223 {"camera", CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA},
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: 257 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
268 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: // Same as notifications. 258 case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING: // Same as notifications.
269 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: 259 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
270 case CONTENT_SETTINGS_TYPE_GEOLOCATION: 260 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
271 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: // ChromeOS only. 261 case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER: // ChromeOS only.
272 case CONTENT_SETTINGS_TYPE_PPAPI_BROKER: 262 case CONTENT_SETTINGS_TYPE_PPAPI_BROKER:
273 case CONTENT_SETTINGS_TYPE_PLUGINS: // Flash. 263 case CONTENT_SETTINGS_TYPE_PLUGINS: // Flash.
274 manager->AddRequest(MakePermissionRequest(it->type)); 264 manager->AddRequest(MakePermissionRequest(it->type));
275 break; 265 break;
276 case CONTENT_SETTINGS_TYPE_DEFAULT: 266 case CONTENT_SETTINGS_TYPE_DEFAULT:
267 // Permissions to request for a "multiple" request. Only mic/camera
268 // requests are grouped together.
277 EXPECT_EQ(kMultipleName, name); 269 EXPECT_EQ(kMultipleName, name);
278 if (base::FeatureList::IsEnabled( 270 manager->AddRequest(
279 features::kUsePermissionManagerForMediaRequests)) { 271 MakePermissionRequest(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
280 for (auto request : kMultipleRequestsWithMedia) 272 manager->AddRequest(
281 manager->AddRequest(MakePermissionRequest(request)); 273 MakePermissionRequest(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
282 } else {
283 for (auto request : kMultipleRequests)
284 manager->AddRequest(MakePermissionRequest(request));
285 }
286 274
287 break; 275 break;
288 default: 276 default:
289 ADD_FAILURE() << "Not a permission type, or one that doesn't prompt."; 277 ADD_FAILURE() << "Not a permission type, or one that doesn't prompt.";
290 return; 278 return;
291 } 279 }
292 manager->DisplayPendingRequests(); 280 manager->DisplayPendingRequests();
293 } 281 }
294 282
295 // Requests before the load event should be bundled into one bubble. 283 // Requests before the load event should be bundled into one bubble.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 1); 329 1);
342 bubble_factory()->WaitForPermissionBubble(); 330 bubble_factory()->WaitForPermissionBubble();
343 331
344 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 332 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
345 browser(), 333 browser(),
346 embedded_test_server()->GetURL("/permissions/requests-before-load.html"), 334 embedded_test_server()->GetURL("/permissions/requests-before-load.html"),
347 1); 335 1);
348 bubble_factory()->WaitForPermissionBubble(); 336 bubble_factory()->WaitForPermissionBubble();
349 337
350 EXPECT_EQ(2, bubble_factory()->show_count()); 338 EXPECT_EQ(2, bubble_factory()->show_count());
351 EXPECT_EQ(4, bubble_factory()->TotalRequestCount()); 339 EXPECT_EQ(2, bubble_factory()->TotalRequestCount());
352 } 340 }
353 341
354 // Navigating twice to the same URL with a hash should be navigation within the 342 // Navigating twice to the same URL with a hash should be navigation within the
355 // page. This means the bubble is only shown once. 343 // page. This means the bubble is only shown once.
356 // http://crbug.com/512849 flaky 344 // http://crbug.com/512849 flaky
357 #if defined(OS_WIN) 345 #if defined(OS_WIN)
358 #define MAYBE_NavTwiceWithHash DISABLED_NavTwiceWithHash 346 #define MAYBE_NavTwiceWithHash DISABLED_NavTwiceWithHash
359 #else 347 #else
360 #define MAYBE_NavTwiceWithHash NavTwiceWithHash 348 #define MAYBE_NavTwiceWithHash NavTwiceWithHash
361 #endif 349 #endif
362 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, 350 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest,
363 MAYBE_NavTwiceWithHash) { 351 MAYBE_NavTwiceWithHash) {
364 ASSERT_TRUE(embedded_test_server()->Start()); 352 ASSERT_TRUE(embedded_test_server()->Start());
365 353
366 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 354 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
367 browser(), 355 browser(),
368 embedded_test_server()->GetURL("/permissions/requests-before-load.html"), 356 embedded_test_server()->GetURL("/permissions/requests-before-load.html"),
369 1); 357 1);
370 bubble_factory()->WaitForPermissionBubble(); 358 bubble_factory()->WaitForPermissionBubble();
371 359
372 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 360 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
373 browser(), 361 browser(),
374 embedded_test_server()->GetURL( 362 embedded_test_server()->GetURL(
375 "/permissions/requests-before-load.html#0"), 363 "/permissions/requests-before-load.html#0"),
376 1); 364 1);
377 bubble_factory()->WaitForPermissionBubble(); 365 bubble_factory()->WaitForPermissionBubble();
378 366
379 EXPECT_EQ(1, bubble_factory()->show_count()); 367 EXPECT_EQ(1, bubble_factory()->show_count());
380 EXPECT_EQ(2, bubble_factory()->TotalRequestCount()); 368 EXPECT_EQ(1, bubble_factory()->TotalRequestCount());
381 } 369 }
382 370
383 // Bubble requests should be shown after in-page navigation. 371 // Bubble requests should be shown after in-page navigation.
384 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, InPageNavigation) { 372 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, InPageNavigation) {
385 ASSERT_TRUE(embedded_test_server()->Start()); 373 ASSERT_TRUE(embedded_test_server()->Start());
386 374
387 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 375 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
388 browser(), 376 browser(),
389 embedded_test_server()->GetURL("/empty.html"), 377 embedded_test_server()->GetURL("/empty.html"),
390 1); 378 1);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 } 503 }
516 504
517 // Host wants to use your MIDI devices. 505 // Host wants to use your MIDI devices.
518 IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeDialog_midi) { 506 IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeDialog_midi) {
519 RunDialog(); 507 RunDialog();
520 } 508 }
521 509
522 // Shows a permissions bubble with multiple requests. 510 // Shows a permissions bubble with multiple requests.
523 IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeDialog_multiple) { 511 IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeDialog_multiple) {
524 RunDialog(); 512 RunDialog();
525
526 {
527 base::test::ScopedFeatureList scoped_feature_list;
528 scoped_feature_list.InitAndEnableFeature(
529 features::kUsePermissionManagerForMediaRequests);
530 RunDialog();
531 }
532 } 513 }
533 514
534 // CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER is ChromeOS only. 515 // CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER is ChromeOS only.
535 #if defined(OS_CHROMEOS) 516 #if defined(OS_CHROMEOS)
536 #define MAYBE_InvokeDialog_protected_media InvokeDialog_protected_media 517 #define MAYBE_InvokeDialog_protected_media InvokeDialog_protected_media
537 #else 518 #else
538 #define MAYBE_InvokeDialog_protected_media DISABLED_InvokeDialog_protected_media 519 #define MAYBE_InvokeDialog_protected_media DISABLED_InvokeDialog_protected_media
539 #endif 520 #endif
540 IN_PROC_BROWSER_TEST_F(PermissionDialogTest, 521 IN_PROC_BROWSER_TEST_F(PermissionDialogTest,
541 MAYBE_InvokeDialog_protected_media) { 522 MAYBE_InvokeDialog_protected_media) {
542 RunDialog(); 523 RunDialog();
543 } 524 }
544 525
545 } // anonymous namespace 526 } // anonymous namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698