Chromium Code Reviews| 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..7664c20ca40eade493be69b0682bdbd92a9e7d10 100644 |
| --- a/chrome/browser/permissions/permission_manager_unittest.cc |
| +++ b/chrome/browser/permissions/permission_manager_unittest.cc |
| @@ -9,17 +9,25 @@ |
| #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 { |
| +int kNoPendingOperation = -1; |
| + |
| class PermissionManagerTestingProfile final : public TestingProfile { |
| public: |
| PermissionManagerTestingProfile() {} |
| @@ -34,7 +42,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 +57,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 +80,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 +104,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 +397,41 @@ 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); |
| + SetPermission(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW); |
|
raymes
2017/06/06 23:34:42
nit: this isn't needed
asimjour1
2017/06/07 15:11:26
Done.
|
| + 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); |
| + SetPermission(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW); |
|
raymes
2017/06/06 23:34:42
nit: this isn't needed
asimjour1
2017/06/07 15:11:26
Done.
|
| + 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) |