| 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..10c5dcce1257f5e359063248f3228ff98dd63b7e 100644
|
| --- a/chrome/browser/permissions/permission_manager_unittest.cc
|
| +++ b/chrome/browser/permissions/permission_manager_unittest.cc
|
| @@ -9,6 +9,7 @@
|
| #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"
|
| @@ -34,7 +35,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;
|
| @@ -48,31 +49,43 @@ class PermissionManagerTest : public testing::Test {
|
| callback_called_(false),
|
| callback_result_(PermissionStatus::ASK) {}
|
|
|
| + void SetUp() override {
|
| + ChromeRenderViewHostTestHarness::SetUp();
|
| + profile_.reset(new PermissionManagerTestingProfile);
|
| + NavigateAndCommit(url_);
|
| + }
|
| +
|
| + void TearDown() override {
|
| + profile_.reset();
|
| + ChromeRenderViewHostTestHarness::TearDown();
|
| + }
|
| +
|
| PermissionManager* GetPermissionManager() {
|
| - return profile_.GetPermissionManager();
|
| + return profile_->GetPermissionManager();
|
| }
|
|
|
| HostContentSettingsMap* GetHostContentSettingsMap() {
|
| - return HostContentSettingsMapFactory::GetForProfile(&profile_);
|
| + return HostContentSettingsMapFactory::GetForProfile(profile_.get());
|
| }
|
|
|
| void CheckPermissionStatus(PermissionType type,
|
| PermissionStatus expected) {
|
| - EXPECT_EQ(expected, GetPermissionManager()->GetPermissionStatus(
|
| - type, url_.GetOrigin(), url_.GetOrigin()));
|
| + EXPECT_EQ(expected, GetPermissionManager()->GetPermissionStatusForFrame(
|
| + type, main_rfh(), url_.GetOrigin()));
|
| }
|
|
|
| void CheckPermissionResult(ContentSettingsType type,
|
| ContentSetting expected_status,
|
| PermissionStatusSource expected_status_source) {
|
| - PermissionResult result = GetPermissionManager()->GetPermissionStatus(
|
| - type, url_.GetOrigin(), url_.GetOrigin());
|
| + PermissionResult result =
|
| + GetPermissionManager()->GetPermissionStatusForFrame(type, main_rfh(),
|
| + url_.GetOrigin());
|
| EXPECT_EQ(expected_status, result.content_setting);
|
| EXPECT_EQ(expected_status_source, result.source);
|
| }
|
|
|
| void SetPermission(ContentSettingsType type, ContentSetting value) {
|
| - HostContentSettingsMapFactory::GetForProfile(&profile_)
|
| + HostContentSettingsMapFactory::GetForProfile(profile_.get())
|
| ->SetContentSettingDefaultScope(url_, url_, type, std::string(), value);
|
| }
|
|
|
| @@ -100,8 +113,7 @@ class PermissionManagerTest : public testing::Test {
|
| 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 +392,29 @@ TEST_F(PermissionManagerTest, SubscribeMIDIPermission) {
|
|
|
| GetPermissionManager()->UnsubscribePermissionStatusChange(subscription_id);
|
| }
|
| +
|
| +// Test that permissions that are allowed in workers are queried correctly.
|
| +TEST_F(PermissionManagerTest, AllowedInWorker) {
|
| + // Notifications is allowed from workers but should ASK by default. This
|
| + // should return DENIED in a worker because it can't prompt.
|
| + EXPECT_EQ(PermissionStatus::DENIED,
|
| + GetPermissionManager()->GetPermissionStatusForWorker(
|
| + PermissionType::NOTIFICATIONS, url()));
|
| +
|
| + // If it is allowed, it should return GRANTED.
|
| + GetHostContentSettingsMap()->SetContentSettingDefaultScope(
|
| + url(), url(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(),
|
| + CONTENT_SETTING_ALLOW);
|
| + EXPECT_EQ(PermissionStatus::GRANTED,
|
| + GetPermissionManager()->GetPermissionStatusForWorker(
|
| + PermissionType::NOTIFICATIONS, url()));
|
| +
|
| + // Geolocation isn't allowed from workers so should return DENIED even if the
|
| + // user has allowed it.
|
| + GetHostContentSettingsMap()->SetContentSettingDefaultScope(
|
| + url(), url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(),
|
| + CONTENT_SETTING_ALLOW);
|
| + EXPECT_EQ(PermissionStatus::DENIED,
|
| + GetPermissionManager()->GetPermissionStatusForWorker(
|
| + PermissionType::GEOLOCATION, url()));
|
| +}
|
|
|