Chromium Code Reviews| 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" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "content/public/common/frame_navigate_params.h" | 21 #include "content/public/common/frame_navigate_params.h" |
| 22 #include "content/public/test/web_contents_tester.h" | 22 #include "content/public/test/web_contents_tester.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
| 26 #include "chrome/browser/download/download_request_infobar_delegate_android.h" | 26 #include "chrome/browser/download/download_request_infobar_delegate_android.h" |
| 27 #include "chrome/browser/infobars/infobar_service.h" | 27 #include "chrome/browser/infobars/infobar_service.h" |
| 28 #else | 28 #else |
| 29 #include "chrome/browser/download/download_permission_request.h" | 29 #include "chrome/browser/download/download_permission_request.h" |
| 30 #include "chrome/browser/permissions/permission_request_manager.h" | 30 #include "chrome/browser/permissions/permission_request_manager.h" |
| 31 #include "chrome/browser/ui/website_settings/mock_permission_bubble_factory.h" | 31 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h" |
| 32 #endif | 32 #endif |
| 33 | 33 |
| 34 using content::WebContents; | 34 using content::WebContents; |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 enum TestingAction { | 37 enum TestingAction { |
| 38 ACCEPT, | 38 ACCEPT, |
| 39 CANCEL, | 39 CANCEL, |
| 40 WAIT | 40 WAIT |
| 41 }; | 41 }; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 TestingAction testing_action_; | 92 TestingAction testing_action_; |
| 93 | 93 |
| 94 DownloadRequestInfoBarDelegateAndroid::FakeCreateCallback | 94 DownloadRequestInfoBarDelegateAndroid::FakeCreateCallback |
| 95 fake_create_callback_; | 95 fake_create_callback_; |
| 96 }; | 96 }; |
| 97 #else | 97 #else |
| 98 class TestingDelegate { | 98 class TestingDelegate { |
| 99 public: | 99 public: |
| 100 void SetUp(WebContents* web_contents) { | 100 void SetUp(WebContents* web_contents) { |
| 101 PermissionRequestManager::CreateForWebContents(web_contents); | 101 PermissionRequestManager::CreateForWebContents(web_contents); |
| 102 mock_permission_bubble_factory_.reset(new MockPermissionBubbleFactory( | 102 mock_permission_request_factory_.reset(new MockPermissionPromptFactory( |
|
raymes
2016/08/01 00:58:13
prompt_factory (here and below)
tsergeant
2016/08/01 23:41:12
Done.
| |
| 103 PermissionRequestManager::FromWebContents(web_contents))); | 103 PermissionRequestManager::FromWebContents(web_contents))); |
| 104 PermissionRequestManager::FromWebContents(web_contents) | 104 PermissionRequestManager::FromWebContents(web_contents) |
| 105 ->DisplayPendingRequests(); | 105 ->DisplayPendingRequests(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void TearDown() { mock_permission_bubble_factory_.reset(); } | 108 void TearDown() { mock_permission_request_factory_.reset(); } |
| 109 | 109 |
| 110 void LoadCompleted(WebContents* web_contents) { | 110 void LoadCompleted(WebContents* web_contents) { |
| 111 mock_permission_bubble_factory_->DocumentOnLoadCompletedInMainFrame(); | 111 mock_permission_request_factory_->DocumentOnLoadCompletedInMainFrame(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void ResetCounts() { mock_permission_bubble_factory_->ResetCounts(); } | 114 void ResetCounts() { mock_permission_request_factory_->ResetCounts(); } |
| 115 | 115 |
| 116 int AllowCount() { return mock_permission_bubble_factory_->show_count(); } | 116 int AllowCount() { return mock_permission_request_factory_->show_count(); } |
| 117 | 117 |
| 118 void UpdateExpectations(TestingAction action) { | 118 void UpdateExpectations(TestingAction action) { |
| 119 // Set expectations for PermissionRequestManager. | 119 // Set expectations for PermissionRequestManager. |
| 120 if (action == ACCEPT) { | 120 if (action == ACCEPT) { |
| 121 mock_permission_bubble_factory_->set_response_type( | 121 mock_permission_request_factory_->set_response_type( |
| 122 PermissionRequestManager::ACCEPT_ALL); | 122 PermissionRequestManager::ACCEPT_ALL); |
| 123 } else if (action == CANCEL) { | 123 } else if (action == CANCEL) { |
| 124 mock_permission_bubble_factory_->set_response_type( | 124 mock_permission_request_factory_->set_response_type( |
| 125 PermissionRequestManager::DENY_ALL); | 125 PermissionRequestManager::DENY_ALL); |
| 126 } else if (action == WAIT) { | 126 } else if (action == WAIT) { |
| 127 mock_permission_bubble_factory_->set_response_type( | 127 mock_permission_request_factory_->set_response_type( |
| 128 PermissionRequestManager::NONE); | 128 PermissionRequestManager::NONE); |
| 129 } else { | 129 } else { |
| 130 mock_permission_bubble_factory_->set_response_type( | 130 mock_permission_request_factory_->set_response_type( |
| 131 PermissionRequestManager::DISMISS); | 131 PermissionRequestManager::DISMISS); |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 | 134 |
| 135 private: | 135 private: |
| 136 std::unique_ptr<MockPermissionBubbleFactory> mock_permission_bubble_factory_; | 136 std::unique_ptr<MockPermissionPromptFactory> |
| 137 mock_permission_request_factory_; | |
| 137 }; | 138 }; |
| 138 #endif | 139 #endif |
| 139 } // namespace | 140 } // namespace |
| 140 | 141 |
| 141 class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { | 142 class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { |
| 142 public: | 143 public: |
| 143 void SetUp() override { | 144 void SetUp() override { |
| 144 ChromeRenderViewHostTestHarness::SetUp(); | 145 ChromeRenderViewHostTestHarness::SetUp(); |
| 145 profile_.reset(new TestingProfile()); | 146 profile_.reset(new TestingProfile()); |
| 146 testing_delegate_.SetUp(web_contents()); | 147 testing_delegate_.SetUp(web_contents()); |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 716 // changing the content setting). | 717 // changing the content setting). |
| 717 UpdateContentSettings(web_contents(), CONTENT_SETTING_ASK); | 718 UpdateContentSettings(web_contents(), CONTENT_SETTING_ASK); |
| 718 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 719 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 719 download_request_limiter_->GetDownloadStatus(web_contents())); | 720 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 720 UpdateExpectations(WAIT); | 721 UpdateExpectations(WAIT); |
| 721 CanDownload(); | 722 CanDownload(); |
| 722 ExpectAndResetCounts(0, 0, 1, __LINE__); | 723 ExpectAndResetCounts(0, 0, 1, __LINE__); |
| 723 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 724 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 724 download_request_limiter_->GetDownloadStatus(web_contents())); | 725 download_request_limiter_->GetDownloadStatus(web_contents())); |
| 725 } | 726 } |
| OLD | NEW |