| Index: chrome/browser/permissions/permission_manager_unittest.cc
|
| diff --git a/chrome/browser/permissions/permission_manager_unittest.cc b/chrome/browser/permissions/permission_manager_unittest.cc
|
| index 3eac84bd33fecd9e4ac834b6d057606d0b67e286..9e8d38584a812aa4b8fea8b7370d5554ee720a94 100644
|
| --- a/chrome/browser/permissions/permission_manager_unittest.cc
|
| +++ b/chrome/browser/permissions/permission_manager_unittest.cc
|
| @@ -9,17 +9,27 @@
|
| #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
|
| #include "chrome/browser/permissions/permission_manager_factory.h"
|
| #include "chrome/browser/permissions/permission_result.h"
|
| +#include "chrome/test/base/chrome_render_view_host_test_harness.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| #include "components/content_settings/core/browser/host_content_settings_map.h"
|
| #include "content/public/browser/permission_type.h"
|
| #include "content/public/test/test_browser_thread_bundle.h"
|
| +#include "device/vr/features/features.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| +#if BUILDFLAG(ENABLE_VR)
|
| +#include "chrome/browser/android/vr_shell/vr_tab_helper.h"
|
| +#endif // BUILDFLAG(ENABLE_VR)
|
| +
|
| using blink::mojom::PermissionStatus;
|
| using content::PermissionType;
|
|
|
| namespace {
|
|
|
| +#if BUILDFLAG(ENABLE_VR)
|
| +int kNoPendingOperation = -1;
|
| +#endif // BUILDFLAG(ENABLE_VR)
|
| +
|
| class PermissionManagerTestingProfile final : public TestingProfile {
|
| public:
|
| PermissionManagerTestingProfile() {}
|
| @@ -34,7 +44,7 @@ class PermissionManagerTestingProfile final : public TestingProfile {
|
|
|
| } // anonymous namespace
|
|
|
| -class PermissionManagerTest : public testing::Test {
|
| +class PermissionManagerTest : public ChromeRenderViewHostTestHarness {
|
| public:
|
| void OnPermissionChange(PermissionStatus permission) {
|
| callback_called_ = true;
|
| @@ -49,11 +59,11 @@ class PermissionManagerTest : public testing::Test {
|
| callback_result_(PermissionStatus::ASK) {}
|
|
|
| PermissionManager* GetPermissionManager() {
|
| - return profile_.GetPermissionManager();
|
| + return profile_->GetPermissionManager();
|
| }
|
|
|
| HostContentSettingsMap* GetHostContentSettingsMap() {
|
| - return HostContentSettingsMapFactory::GetForProfile(&profile_);
|
| + return HostContentSettingsMapFactory::GetForProfile(profile_.get());
|
| }
|
|
|
| void CheckPermissionStatus(PermissionType type,
|
| @@ -72,7 +82,7 @@ class PermissionManagerTest : public testing::Test {
|
| }
|
|
|
| void SetPermission(ContentSettingsType type, ContentSetting value) {
|
| - HostContentSettingsMapFactory::GetForProfile(&profile_)
|
| + HostContentSettingsMapFactory::GetForProfile(profile_.get())
|
| ->SetContentSettingDefaultScope(url_, url_, type, std::string(), value);
|
| }
|
|
|
| @@ -96,12 +106,21 @@ class PermissionManagerTest : public testing::Test {
|
| }
|
|
|
| private:
|
| + void SetUp() override {
|
| + ChromeRenderViewHostTestHarness::SetUp();
|
| + profile_.reset(new PermissionManagerTestingProfile());
|
| + }
|
| +
|
| + void TearDown() override {
|
| + profile_.reset();
|
| + ChromeRenderViewHostTestHarness::TearDown();
|
| + }
|
| +
|
| const GURL url_;
|
| const GURL other_url_;
|
| bool callback_called_;
|
| PermissionStatus callback_result_;
|
| - content::TestBrowserThreadBundle thread_bundle_;
|
| - PermissionManagerTestingProfile profile_;
|
| + std::unique_ptr<PermissionManagerTestingProfile> profile_;
|
| };
|
|
|
| TEST_F(PermissionManagerTest, GetPermissionStatusDefault) {
|
| @@ -380,3 +399,39 @@ TEST_F(PermissionManagerTest, SubscribeMIDIPermission) {
|
|
|
| GetPermissionManager()->UnsubscribePermissionStatusChange(subscription_id);
|
| }
|
| +
|
| +#if BUILDFLAG(ENABLE_VR)
|
| +TEST_F(PermissionManagerTest, SuppressPermissionRequests) {
|
| + content::WebContents* contents = web_contents();
|
| + vr_shell::VrTabHelper::CreateForWebContents(contents);
|
| + NavigateAndCommit(url());
|
| +
|
| + SetPermission(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW);
|
| + GetPermissionManager()->RequestPermission(
|
| + PermissionType::NOTIFICATIONS, main_rfh(), url(), true,
|
| + base::Bind(&PermissionManagerTest::OnPermissionChange,
|
| + base::Unretained(this)));
|
| + EXPECT_TRUE(callback_called());
|
| + EXPECT_EQ(PermissionStatus::GRANTED, callback_result());
|
| +
|
| + vr_shell::VrTabHelper* vr_tab_helper =
|
| + vr_shell::VrTabHelper::FromWebContents(contents);
|
| + vr_tab_helper->SetIsInVr(true);
|
| + EXPECT_EQ(
|
| + kNoPendingOperation,
|
| + GetPermissionManager()->RequestPermission(
|
| + PermissionType::NOTIFICATIONS, contents->GetMainFrame(), url(), false,
|
| + base::Bind(&PermissionManagerTest::OnPermissionChange,
|
| + base::Unretained(this))));
|
| + EXPECT_TRUE(callback_called());
|
| + EXPECT_EQ(PermissionStatus::DENIED, callback_result());
|
| +
|
| + vr_tab_helper->SetIsInVr(false);
|
| + GetPermissionManager()->RequestPermission(
|
| + PermissionType::NOTIFICATIONS, main_rfh(), url(), false,
|
| + base::Bind(&PermissionManagerTest::OnPermissionChange,
|
| + base::Unretained(this)));
|
| + EXPECT_TRUE(callback_called());
|
| + EXPECT_EQ(PermissionStatus::GRANTED, callback_result());
|
| +}
|
| +#endif // BUILDFLAG(ENABLE_VR)
|
|
|