| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_context_base.h" | 5 #include "chrome/browser/permissions/permission_context_base.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/test/mock_entropy_provider.h" | 13 #include "base/test/mock_entropy_provider.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 16 #include "chrome/browser/infobars/infobar_service.h" | 16 #include "chrome/browser/infobars/infobar_service.h" |
| 17 #include "chrome/browser/permissions/permission_queue_controller.h" | 17 #include "chrome/browser/permissions/permission_queue_controller.h" |
| 18 #include "chrome/browser/permissions/permission_request_id.h" | 18 #include "chrome/browser/permissions/permission_request_id.h" |
| 19 #include "chrome/browser/permissions/permission_util.h" | 19 #include "chrome/browser/permissions/permission_util.h" |
| 20 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | |
| 21 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| 24 #include "components/content_settings/core/browser/host_content_settings_map.h" | 23 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 25 #include "components/content_settings/core/common/content_settings.h" | 24 #include "components/content_settings/core/common/content_settings.h" |
| 26 #include "components/content_settings/core/common/content_settings_types.h" | 25 #include "components/content_settings/core/common/content_settings_types.h" |
| 27 #include "components/variations/variations_associated_data.h" | 26 #include "components/variations/variations_associated_data.h" |
| 28 #include "content/public/browser/permission_type.h" | 27 #include "content/public/browser/permission_type.h" |
| 29 #include "content/public/browser/render_frame_host.h" | 28 #include "content/public/browser/render_frame_host.h" |
| 30 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/test/mock_render_process_host.h" | 30 #include "content/public/test/mock_render_process_host.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 32 |
| 34 #if defined(OS_ANDROID) | 33 #if defined(OS_ANDROID) |
| 35 #include "chrome/browser/permissions/permission_queue_controller.h" | 34 #include "chrome/browser/permissions/permission_queue_controller.h" |
| 36 #else | 35 #else |
| 37 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 36 #include "chrome/browser/permissions/permission_request_manager.h" |
| 38 #endif | 37 #endif |
| 39 | 38 |
| 40 const char* kPermissionsKillSwitchFieldStudy = | 39 const char* kPermissionsKillSwitchFieldStudy = |
| 41 PermissionContextBase::kPermissionsKillSwitchFieldStudy; | 40 PermissionContextBase::kPermissionsKillSwitchFieldStudy; |
| 42 const char* kPermissionsKillSwitchBlockedValue = | 41 const char* kPermissionsKillSwitchBlockedValue = |
| 43 PermissionContextBase::kPermissionsKillSwitchBlockedValue; | 42 PermissionContextBase::kPermissionsKillSwitchBlockedValue; |
| 44 const char kPermissionsKillSwitchTestGroup[] = "TestGroup"; | 43 const char kPermissionsKillSwitchTestGroup[] = "TestGroup"; |
| 45 | 44 |
| 46 class TestPermissionContext : public PermissionContextBase { | 45 class TestPermissionContext : public PermissionContextBase { |
| 47 public: | 46 public: |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 ContentSetting response) { | 114 ContentSetting response) { |
| 116 DCHECK(response == CONTENT_SETTING_ALLOW || | 115 DCHECK(response == CONTENT_SETTING_ALLOW || |
| 117 response == CONTENT_SETTING_BLOCK || | 116 response == CONTENT_SETTING_BLOCK || |
| 118 response == CONTENT_SETTING_ASK); | 117 response == CONTENT_SETTING_ASK); |
| 119 #if defined(OS_ANDROID) | 118 #if defined(OS_ANDROID) |
| 120 bool update_content_setting = response != CONTENT_SETTING_ASK; | 119 bool update_content_setting = response != CONTENT_SETTING_ASK; |
| 121 bool allowed = response == CONTENT_SETTING_ALLOW; | 120 bool allowed = response == CONTENT_SETTING_ALLOW; |
| 122 context->GetInfoBarController()->OnPermissionSet( | 121 context->GetInfoBarController()->OnPermissionSet( |
| 123 id, url, url, update_content_setting, allowed); | 122 id, url, url, update_content_setting, allowed); |
| 124 #else | 123 #else |
| 125 PermissionBubbleManager* manager = | 124 PermissionRequestManager* manager = |
| 126 PermissionBubbleManager::FromWebContents(web_contents()); | 125 PermissionRequestManager::FromWebContents(web_contents()); |
| 127 switch (response) { | 126 switch (response) { |
| 128 case CONTENT_SETTING_ALLOW: | 127 case CONTENT_SETTING_ALLOW: |
| 129 manager->Accept(); | 128 manager->Accept(); |
| 130 break; | 129 break; |
| 131 case CONTENT_SETTING_BLOCK: | 130 case CONTENT_SETTING_BLOCK: |
| 132 manager->Deny(); | 131 manager->Deny(); |
| 133 break; | 132 break; |
| 134 case CONTENT_SETTING_ASK: | 133 case CONTENT_SETTING_ASK: |
| 135 manager->Closing(); | 134 manager->Closing(); |
| 136 break; | 135 break; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 EXPECT_EQ(response, permission_context.GetContentSettingFromMap(url, url)); | 306 EXPECT_EQ(response, permission_context.GetContentSettingFromMap(url, url)); |
| 308 } | 307 } |
| 309 | 308 |
| 310 private: | 309 private: |
| 311 // ChromeRenderViewHostTestHarness: | 310 // ChromeRenderViewHostTestHarness: |
| 312 void SetUp() override { | 311 void SetUp() override { |
| 313 ChromeRenderViewHostTestHarness::SetUp(); | 312 ChromeRenderViewHostTestHarness::SetUp(); |
| 314 #if defined(OS_ANDROID) | 313 #if defined(OS_ANDROID) |
| 315 InfoBarService::CreateForWebContents(web_contents()); | 314 InfoBarService::CreateForWebContents(web_contents()); |
| 316 #else | 315 #else |
| 317 PermissionBubbleManager::CreateForWebContents(web_contents()); | 316 PermissionRequestManager::CreateForWebContents(web_contents()); |
| 318 #endif | 317 #endif |
| 319 } | 318 } |
| 320 | 319 |
| 321 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); | 320 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); |
| 322 }; | 321 }; |
| 323 | 322 |
| 324 // Simulates clicking Accept. The permission should be granted and | 323 // Simulates clicking Accept. The permission should be granted and |
| 325 // saved for future use. | 324 // saved for future use. |
| 326 TEST_F(PermissionContextBaseTests, TestAskAndGrant) { | 325 TEST_F(PermissionContextBaseTests, TestAskAndGrant) { |
| 327 TestAskAndGrant_TestContent(); | 326 TestAskAndGrant_TestContent(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 TestParallelRequests(CONTENT_SETTING_ALLOW); | 419 TestParallelRequests(CONTENT_SETTING_ALLOW); |
| 421 } | 420 } |
| 422 | 421 |
| 423 TEST_F(PermissionContextBaseTests, TestParallelRequestsBlocked) { | 422 TEST_F(PermissionContextBaseTests, TestParallelRequestsBlocked) { |
| 424 TestParallelRequests(CONTENT_SETTING_BLOCK); | 423 TestParallelRequests(CONTENT_SETTING_BLOCK); |
| 425 } | 424 } |
| 426 | 425 |
| 427 TEST_F(PermissionContextBaseTests, TestParallelRequestsDismissed) { | 426 TEST_F(PermissionContextBaseTests, TestParallelRequestsDismissed) { |
| 428 TestParallelRequests(CONTENT_SETTING_ASK); | 427 TestParallelRequests(CONTENT_SETTING_ASK); |
| 429 } | 428 } |
| OLD | NEW |