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

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

Issue 2975593002: [vr] Deny permission requests in VR mode
Patch Set: . Created 3 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/permissions/permission_manager.h" 5 #include "chrome/browser/permissions/permission_manager.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/permissions/permission_manager_factory.h" 10 #include "chrome/browser/permissions/permission_manager_factory.h"
11 #include "chrome/browser/permissions/permission_request_manager.h" 11 #include "chrome/browser/permissions/permission_request_manager.h"
12 #include "chrome/browser/permissions/permission_result.h" 12 #include "chrome/browser/permissions/permission_result.h"
13 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" 13 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h"
14 #include "chrome/browser/vr/vr_tab_helper.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
16 #include "components/content_settings/core/browser/host_content_settings_map.h" 17 #include "components/content_settings/core/browser/host_content_settings_map.h"
17 #include "content/public/browser/permission_type.h" 18 #include "content/public/browser/permission_type.h"
18 #include "content/public/test/test_browser_thread_bundle.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "device/vr/features/features.h" 20 #include "device/vr/features/features.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 #if BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID)
23 #include "chrome/browser/android/vr_shell/vr_tab_helper.h"
24 #endif // BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID)
25
26 using blink::mojom::PermissionStatus; 23 using blink::mojom::PermissionStatus;
27 using content::PermissionType; 24 using content::PermissionType;
28 25
29 namespace { 26 namespace {
30 27
31 #if BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID)
32 int kNoPendingOperation = -1; 28 int kNoPendingOperation = -1;
33 #endif // BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID)
34 29
35 class PermissionManagerTestingProfile final : public TestingProfile { 30 class PermissionManagerTestingProfile final : public TestingProfile {
36 public: 31 public:
37 PermissionManagerTestingProfile() {} 32 PermissionManagerTestingProfile() {}
38 ~PermissionManagerTestingProfile() override {} 33 ~PermissionManagerTestingProfile() override {}
39 34
40 PermissionManager* GetPermissionManager() override { 35 PermissionManager* GetPermissionManager() override {
41 return PermissionManagerFactory::GetForProfile(this); 36 return PermissionManagerFactory::GetForProfile(this);
42 } 37 }
43 38
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 GetHostContentSettingsMap()->SetContentSettingDefaultScope( 394 GetHostContentSettingsMap()->SetContentSettingDefaultScope(
400 url(), url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), 395 url(), url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(),
401 CONTENT_SETTING_ALLOW); 396 CONTENT_SETTING_ALLOW);
402 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::GRANTED); 397 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::GRANTED);
403 398
404 EXPECT_FALSE(callback_called()); 399 EXPECT_FALSE(callback_called());
405 400
406 GetPermissionManager()->UnsubscribePermissionStatusChange(subscription_id); 401 GetPermissionManager()->UnsubscribePermissionStatusChange(subscription_id);
407 } 402 }
408 403
409 #if BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID)
410 TEST_F(PermissionManagerTest, SuppressPermissionRequests) { 404 TEST_F(PermissionManagerTest, SuppressPermissionRequests) {
411 content::WebContents* contents = web_contents(); 405 content::WebContents* contents = web_contents();
412 vr_shell::VrTabHelper::CreateForWebContents(contents); 406 vr::VrTabHelper::CreateForWebContents(contents);
413 NavigateAndCommit(url()); 407 NavigateAndCommit(url());
414 408
415 SetPermission(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW); 409 SetPermission(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
416 GetPermissionManager()->RequestPermission( 410 GetPermissionManager()->RequestPermission(
417 PermissionType::NOTIFICATIONS, main_rfh(), url(), true, 411 PermissionType::NOTIFICATIONS, main_rfh(), url(), true,
418 base::Bind(&PermissionManagerTest::OnPermissionChange, 412 base::Bind(&PermissionManagerTest::OnPermissionChange,
419 base::Unretained(this))); 413 base::Unretained(this)));
420 EXPECT_TRUE(callback_called()); 414 EXPECT_TRUE(callback_called());
421 EXPECT_EQ(PermissionStatus::GRANTED, callback_result()); 415 EXPECT_EQ(PermissionStatus::GRANTED, callback_result());
422 416
423 vr_shell::VrTabHelper* vr_tab_helper = 417 vr::VrTabHelper* vr_tab_helper = vr::VrTabHelper::FromWebContents(contents);
424 vr_shell::VrTabHelper::FromWebContents(contents);
425 vr_tab_helper->SetIsInVr(true); 418 vr_tab_helper->SetIsInVr(true);
426 EXPECT_EQ( 419 EXPECT_EQ(
427 kNoPendingOperation, 420 kNoPendingOperation,
428 GetPermissionManager()->RequestPermission( 421 GetPermissionManager()->RequestPermission(
429 PermissionType::NOTIFICATIONS, contents->GetMainFrame(), url(), false, 422 PermissionType::NOTIFICATIONS, contents->GetMainFrame(), url(), false,
430 base::Bind(&PermissionManagerTest::OnPermissionChange, 423 base::Bind(&PermissionManagerTest::OnPermissionChange,
431 base::Unretained(this)))); 424 base::Unretained(this))));
432 EXPECT_TRUE(callback_called()); 425 EXPECT_TRUE(callback_called());
433 EXPECT_EQ(PermissionStatus::DENIED, callback_result()); 426 EXPECT_EQ(PermissionStatus::DENIED, callback_result());
434 427
435 vr_tab_helper->SetIsInVr(false); 428 vr_tab_helper->SetIsInVr(false);
436 GetPermissionManager()->RequestPermission( 429 GetPermissionManager()->RequestPermission(
437 PermissionType::NOTIFICATIONS, main_rfh(), url(), false, 430 PermissionType::NOTIFICATIONS, main_rfh(), url(), false,
438 base::Bind(&PermissionManagerTest::OnPermissionChange, 431 base::Bind(&PermissionManagerTest::OnPermissionChange,
439 base::Unretained(this))); 432 base::Unretained(this)));
440 EXPECT_TRUE(callback_called()); 433 EXPECT_TRUE(callback_called());
441 EXPECT_EQ(PermissionStatus::GRANTED, callback_result()); 434 EXPECT_EQ(PermissionStatus::GRANTED, callback_result());
442 } 435 }
443 #endif // BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID)
444 436
445 TEST_F(PermissionManagerTest, PermissionIgnoredCleanup) { 437 TEST_F(PermissionManagerTest, PermissionIgnoredCleanup) {
446 content::WebContents* contents = web_contents(); 438 content::WebContents* contents = web_contents();
447 PermissionRequestManager::CreateForWebContents(contents); 439 PermissionRequestManager::CreateForWebContents(contents);
448 PermissionRequestManager* manager = 440 PermissionRequestManager* manager =
449 PermissionRequestManager::FromWebContents(contents); 441 PermissionRequestManager::FromWebContents(contents);
450 auto prompt_factory = base::MakeUnique<MockPermissionPromptFactory>(manager); 442 auto prompt_factory = base::MakeUnique<MockPermissionPromptFactory>(manager);
451 manager->DisplayPendingRequests(); 443 manager->DisplayPendingRequests();
452 444
453 NavigateAndCommit(url()); 445 NavigateAndCommit(url());
454 446
455 GetPermissionManager()->RequestPermission( 447 GetPermissionManager()->RequestPermission(
456 PermissionType::VIDEO_CAPTURE, main_rfh(), url(), /*user_gesture=*/true, 448 PermissionType::VIDEO_CAPTURE, main_rfh(), url(), /*user_gesture=*/true,
457 base::Bind(&PermissionManagerTest::OnPermissionChange, 449 base::Bind(&PermissionManagerTest::OnPermissionChange,
458 base::Unretained(this))); 450 base::Unretained(this)));
459 451
460 EXPECT_FALSE(PendingRequestsEmpty()); 452 EXPECT_FALSE(PendingRequestsEmpty());
461 453
462 NavigateAndCommit(GURL("https://foobar.com")); 454 NavigateAndCommit(GURL("https://foobar.com"));
463 455
464 EXPECT_FALSE(callback_called()); 456 EXPECT_FALSE(callback_called());
465 EXPECT_TRUE(PendingRequestsEmpty()); 457 EXPECT_TRUE(PendingRequestsEmpty());
466 } 458 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_manager.cc ('k') | chrome/browser/ui/android/login_handler_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698