Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_result.h" | 11 #include "chrome/browser/permissions/permission_result.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 13 #include "components/content_settings/core/browser/host_content_settings_map.h" | 13 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 14 #include "content/public/browser/permission_type.h" | 14 #include "content/public/browser/permission_type.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 16 #include "content/public/test/test_renderer_host.h" | |
| 17 #include "device/vr/features/features.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 19 |
| 20 #if BUILDFLAG(ENABLE_VR) | |
| 21 #include "chrome/browser/android/vr_shell/vr_tab_helper.h" | |
| 22 #endif // BUILDFLAG(ENABLE_VR) | |
| 23 | |
| 18 using blink::mojom::PermissionStatus; | 24 using blink::mojom::PermissionStatus; |
| 19 using content::PermissionType; | 25 using content::PermissionType; |
| 20 | 26 |
| 21 namespace { | 27 namespace { |
| 22 | 28 |
| 29 int kNoPendingOperation = -1; | |
| 30 | |
| 23 class PermissionManagerTestingProfile final : public TestingProfile { | 31 class PermissionManagerTestingProfile final : public TestingProfile { |
| 24 public: | 32 public: |
| 25 PermissionManagerTestingProfile() {} | 33 PermissionManagerTestingProfile() {} |
| 26 ~PermissionManagerTestingProfile() override {} | 34 ~PermissionManagerTestingProfile() override {} |
| 27 | 35 |
| 28 PermissionManager* GetPermissionManager() override { | 36 PermissionManager* GetPermissionManager() override { |
| 29 return PermissionManagerFactory::GetForProfile(this); | 37 return PermissionManagerFactory::GetForProfile(this); |
| 30 } | 38 } |
| 31 | 39 |
| 32 DISALLOW_COPY_AND_ASSIGN(PermissionManagerTestingProfile); | 40 DISALLOW_COPY_AND_ASSIGN(PermissionManagerTestingProfile); |
| 33 }; | 41 }; |
| 34 | 42 |
| 35 } // anonymous namespace | 43 } // anonymous namespace |
| 36 | 44 |
| 37 class PermissionManagerTest : public testing::Test { | 45 class PermissionManagerTest : public content::RenderViewHostTestHarness { |
| 38 public: | 46 public: |
| 39 void OnPermissionChange(PermissionStatus permission) { | 47 void OnPermissionChange(PermissionStatus permission) { |
| 40 callback_called_ = true; | 48 callback_called_ = true; |
| 41 callback_result_ = permission; | 49 callback_result_ = permission; |
| 42 } | 50 } |
| 43 | 51 |
| 44 protected: | 52 protected: |
| 45 PermissionManagerTest() | 53 PermissionManagerTest() |
| 46 : url_("https://example.com"), | 54 : url_("https://example.com"), |
| 47 other_url_("https://foo.com"), | 55 other_url_("https://foo.com"), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 callback_result_ = PermissionStatus::ASK; | 103 callback_result_ = PermissionStatus::ASK; |
| 96 } | 104 } |
| 97 | 105 |
| 98 private: | 106 private: |
| 99 const GURL url_; | 107 const GURL url_; |
| 100 const GURL other_url_; | 108 const GURL other_url_; |
| 101 bool callback_called_; | 109 bool callback_called_; |
| 102 PermissionStatus callback_result_; | 110 PermissionStatus callback_result_; |
| 103 content::TestBrowserThreadBundle thread_bundle_; | 111 content::TestBrowserThreadBundle thread_bundle_; |
| 104 PermissionManagerTestingProfile profile_; | 112 PermissionManagerTestingProfile profile_; |
| 113 void SetUp() override { RenderViewHostTestHarness::SetUp(); } | |
| 114 | |
| 115 void TearDown() override { RenderViewHostTestHarness::TearDown(); } | |
|
raymes
2017/05/30 00:32:32
nit: methods always go above member variables
asimjour1
2017/05/30 18:27:45
Done.
| |
| 105 }; | 116 }; |
| 106 | 117 |
| 107 TEST_F(PermissionManagerTest, GetPermissionStatusDefault) { | 118 TEST_F(PermissionManagerTest, GetPermissionStatusDefault) { |
| 108 CheckPermissionStatus(PermissionType::MIDI_SYSEX, PermissionStatus::ASK); | 119 CheckPermissionStatus(PermissionType::MIDI_SYSEX, PermissionStatus::ASK); |
| 109 CheckPermissionStatus(PermissionType::PUSH_MESSAGING, PermissionStatus::ASK); | 120 CheckPermissionStatus(PermissionType::PUSH_MESSAGING, PermissionStatus::ASK); |
| 110 CheckPermissionStatus(PermissionType::NOTIFICATIONS, PermissionStatus::ASK); | 121 CheckPermissionStatus(PermissionType::NOTIFICATIONS, PermissionStatus::ASK); |
| 111 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::ASK); | 122 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::ASK); |
| 112 #if defined(OS_ANDROID) | 123 #if defined(OS_ANDROID) |
| 113 CheckPermissionStatus(PermissionType::PROTECTED_MEDIA_IDENTIFIER, | 124 CheckPermissionStatus(PermissionType::PROTECTED_MEDIA_IDENTIFIER, |
| 114 PermissionStatus::ASK); | 125 PermissionStatus::ASK); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::ASK); | 384 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::ASK); |
| 374 GetHostContentSettingsMap()->SetContentSettingDefaultScope( | 385 GetHostContentSettingsMap()->SetContentSettingDefaultScope( |
| 375 url(), url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), | 386 url(), url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), |
| 376 CONTENT_SETTING_ALLOW); | 387 CONTENT_SETTING_ALLOW); |
| 377 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::GRANTED); | 388 CheckPermissionStatus(PermissionType::GEOLOCATION, PermissionStatus::GRANTED); |
| 378 | 389 |
| 379 EXPECT_FALSE(callback_called()); | 390 EXPECT_FALSE(callback_called()); |
| 380 | 391 |
| 381 GetPermissionManager()->UnsubscribePermissionStatusChange(subscription_id); | 392 GetPermissionManager()->UnsubscribePermissionStatusChange(subscription_id); |
| 382 } | 393 } |
| 394 | |
| 395 TEST_F(PermissionManagerTest, SuppressPermissionRequests) { | |
| 396 content::WebContents* contents = web_contents(); | |
| 397 EXPECT_NE(kNoPendingOperation, | |
| 398 GetPermissionManager()->RequestPermission( | |
| 399 PermissionType::GEOLOCATION, web_contents()->GetMainFrame(), | |
| 400 url(), true, | |
| 401 base::Bind(&PermissionManagerTest::OnPermissionChange, | |
| 402 base::Unretained(this)))); | |
| 403 | |
| 404 #if BUILDFLAG(ENABLE_VR) | |
| 405 vr_shell::VrTabHelper* vr_tab_helper = | |
| 406 vr_shell::VrTabHelper::FromWebContents(contents); | |
| 407 | |
| 408 vr_tab_helper->SetIsInVr(true); | |
| 409 EXPECT_EQ(kNoPendingOperation, | |
| 410 GetPermissionManager()->RequestPermission( | |
| 411 PermissionType::GEOLOCATION, web_contents()->GetMainFrame(), | |
| 412 url(), true, | |
| 413 base::Bind(&PermissionManagerTest::OnPermissionChange, | |
| 414 base::Unretained(this)))); | |
| 415 | |
| 416 vr_tab_helper->SetIsInVr(false); | |
| 417 EXPECT_NE(kNoPendingOperation, | |
| 418 GetPermissionManager()->RequestPermission( | |
| 419 PermissionType::GEOLOCATION, web_contents()->GetMainFrame(), | |
| 420 url(), true, | |
| 421 base::Bind(&PermissionManagerTest::OnPermissionChange, | |
| 422 base::Unretained(this)))); | |
|
raymes
2017/05/30 00:32:32
Please check callback_called() and callback_result
asimjour1
2017/05/30 18:27:45
Done.
| |
| 423 #endif // BUILDFLAG(ENABLE_VR) | |
| 424 } | |
| OLD | NEW |