| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/download/download_request_limiter.h" | 5 #include "chrome/browser/download/download_request_limiter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 15 #include "components/content_settings/core/browser/host_content_settings_map.h" | 15 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 16 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
| 17 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_details.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/common/frame_navigate_params.h" | 21 #include "content/public/common/frame_navigate_params.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 #if defined(OS_ANDROID) | 24 #if defined(OS_ANDROID) |
| 25 #include "chrome/browser/download/download_request_infobar_delegate_android.h" | 25 #include "chrome/browser/download/download_request_infobar_delegate_android.h" |
| 26 #include "chrome/browser/infobars/infobar_service.h" | 26 #include "chrome/browser/infobars/infobar_service.h" |
| 27 #else | 27 #else |
| 28 #include "chrome/browser/download/download_permission_request.h" | 28 #include "chrome/browser/download/download_permission_request.h" |
| 29 #include "chrome/browser/permissions/permission_request_manager.h" |
| 29 #include "chrome/browser/ui/website_settings/mock_permission_bubble_factory.h" | 30 #include "chrome/browser/ui/website_settings/mock_permission_bubble_factory.h" |
| 30 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 using content::WebContents; | 33 using content::WebContents; |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 enum TestingAction { | 36 enum TestingAction { |
| 37 ACCEPT, | 37 ACCEPT, |
| 38 CANCEL, | 38 CANCEL, |
| 39 WAIT | 39 WAIT |
| 40 }; | 40 }; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // The action that FakeCreate() should take. | 90 // The action that FakeCreate() should take. |
| 91 TestingAction testing_action_; | 91 TestingAction testing_action_; |
| 92 | 92 |
| 93 DownloadRequestInfoBarDelegateAndroid::FakeCreateCallback | 93 DownloadRequestInfoBarDelegateAndroid::FakeCreateCallback |
| 94 fake_create_callback_; | 94 fake_create_callback_; |
| 95 }; | 95 }; |
| 96 #else | 96 #else |
| 97 class TestingDelegate { | 97 class TestingDelegate { |
| 98 public: | 98 public: |
| 99 void SetUp(WebContents* web_contents) { | 99 void SetUp(WebContents* web_contents) { |
| 100 PermissionBubbleManager::CreateForWebContents(web_contents); | 100 PermissionRequestManager::CreateForWebContents(web_contents); |
| 101 mock_permission_bubble_factory_.reset(new MockPermissionBubbleFactory( | 101 mock_permission_bubble_factory_.reset(new MockPermissionBubbleFactory( |
| 102 false, PermissionBubbleManager::FromWebContents(web_contents))); | 102 false, PermissionRequestManager::FromWebContents(web_contents))); |
| 103 PermissionBubbleManager::FromWebContents(web_contents) | 103 PermissionRequestManager::FromWebContents(web_contents) |
| 104 ->DisplayPendingRequests(); | 104 ->DisplayPendingRequests(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void TearDown() { mock_permission_bubble_factory_.reset(); } | 107 void TearDown() { mock_permission_bubble_factory_.reset(); } |
| 108 | 108 |
| 109 void LoadCompleted(WebContents* web_contents) { | 109 void LoadCompleted(WebContents* web_contents) { |
| 110 mock_permission_bubble_factory_->DocumentOnLoadCompletedInMainFrame(); | 110 mock_permission_bubble_factory_->DocumentOnLoadCompletedInMainFrame(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void ResetCounts() { mock_permission_bubble_factory_->ResetCounts(); } | 113 void ResetCounts() { mock_permission_bubble_factory_->ResetCounts(); } |
| 114 | 114 |
| 115 int AllowCount() { return mock_permission_bubble_factory_->show_count(); } | 115 int AllowCount() { return mock_permission_bubble_factory_->show_count(); } |
| 116 | 116 |
| 117 void UpdateExpectations(TestingAction action) { | 117 void UpdateExpectations(TestingAction action) { |
| 118 // Set expectations for PermissionBubbleManager. | 118 // Set expectations for PermissionRequestManager. |
| 119 if (action == ACCEPT) { | 119 if (action == ACCEPT) { |
| 120 mock_permission_bubble_factory_->set_response_type( | 120 mock_permission_bubble_factory_->set_response_type( |
| 121 PermissionBubbleManager::ACCEPT_ALL); | 121 PermissionRequestManager::ACCEPT_ALL); |
| 122 } else if (action == CANCEL) { | 122 } else if (action == CANCEL) { |
| 123 mock_permission_bubble_factory_->set_response_type( | 123 mock_permission_bubble_factory_->set_response_type( |
| 124 PermissionBubbleManager::DENY_ALL); | 124 PermissionRequestManager::DENY_ALL); |
| 125 } else if (action == WAIT) { | 125 } else if (action == WAIT) { |
| 126 mock_permission_bubble_factory_->set_response_type( | 126 mock_permission_bubble_factory_->set_response_type( |
| 127 PermissionBubbleManager::NONE); | 127 PermissionRequestManager::NONE); |
| 128 } else { | 128 } else { |
| 129 mock_permission_bubble_factory_->set_response_type( | 129 mock_permission_bubble_factory_->set_response_type( |
| 130 PermissionBubbleManager::DISMISS); | 130 PermissionRequestManager::DISMISS); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 private: | 134 private: |
| 135 std::unique_ptr<MockPermissionBubbleFactory> mock_permission_bubble_factory_; | 135 std::unique_ptr<MockPermissionBubbleFactory> mock_permission_bubble_factory_; |
| 136 }; | 136 }; |
| 137 #endif | 137 #endif |
| 138 } // namespace | 138 } // namespace |
| 139 | 139 |
| 140 class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { | 140 class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 // changing the content setting). | 582 // changing the content setting). |
| 583 UpdateContentSettings(web_contents(), CONTENT_SETTING_ASK); | 583 UpdateContentSettings(web_contents(), CONTENT_SETTING_ASK); |
| 584 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 584 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 585 download_request_limiter_->GetDownloadStatus(web_contents())); | 585 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 586 UpdateExpectations(WAIT); | 586 UpdateExpectations(WAIT); |
| 587 CanDownload(); | 587 CanDownload(); |
| 588 ExpectAndResetCounts(0, 0, 1, __LINE__); | 588 ExpectAndResetCounts(0, 0, 1, __LINE__); |
| 589 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 589 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 590 download_request_limiter_->GetDownloadStatus(web_contents())); | 590 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 591 } | 591 } |
| OLD | NEW |