Chromium Code Reviews| Index: chrome/browser/download/download_request_limiter_unittest.cc |
| diff --git a/chrome/browser/download/download_request_limiter_unittest.cc b/chrome/browser/download/download_request_limiter_unittest.cc |
| index fbb8708e2ffe136737d33389efef17cdf5343fc4..41f2d85088a38298e062eb751dbfa35974bae2fc 100644 |
| --- a/chrome/browser/download/download_request_limiter_unittest.cc |
| +++ b/chrome/browser/download/download_request_limiter_unittest.cc |
| @@ -8,12 +8,15 @@ |
| #include "base/command_line.h" |
| #include "base/run_loop.h" |
| #include "build/build_config.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/common/chrome_switches.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/navigation_controller.h" |
| #include "content/public/browser/navigation_details.h" |
| +#include "content/public/browser/notification_service.h" |
| +#include "content/public/browser/notification_source.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/common/frame_navigate_params.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -195,6 +198,18 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { |
| testing_delegate_.ResetCounts(); |
| } |
| + void UpdateContentSettings(WebContents* web_contents, |
| + ContentSetting setting) { |
| + // Ensure a download state exists. |
| + download_request_limiter_->GetDownloadState(web_contents, NULL, true); |
|
asanka
2016/02/08 15:02:14
NULL -> nullptr
dominickn
2016/02/11 01:25:53
Done. Also updated other uses in this file.
|
| + SetHostContentSetting(web_contents, setting); |
| + |
| + content::NotificationService::current()->Notify( |
| + chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| + content::Source<WebContents>(web_contents), |
| + content::NotificationService::NoDetails()); |
| + } |
| + |
| protected: |
| void ContinueDownload(bool allow) { |
| if (allow) { |
| @@ -485,3 +500,37 @@ TEST_F(DownloadRequestLimiterTest, |
| ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| download_request_limiter_->GetDownloadStatus(web_contents())); |
| } |
| + |
| +TEST_F(DownloadRequestLimiterTest, |
| + DownloadRequestLimiter_ContentSettingChanged) { |
|
asanka
2016/02/08 15:02:14
The current behavior doesn't reset the download co
dominickn
2016/02/11 01:25:53
Not sure I understood this 100%, but I added a bun
|
| + NavigateAndCommit(GURL("http://foo.com/bar")); |
| + ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
| + download_request_limiter_->GetDownloadStatus(web_contents())); |
| + |
| + // Set the content setting to allow and send the notification. Ensure that the |
| + // limiter states update to match. |
| + UpdateContentSettings(web_contents(), CONTENT_SETTING_ALLOW); |
| + ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, |
| + download_request_limiter_->GetDownloadStatus(web_contents())); |
| + |
| + // Ask to download and assert we are still in allow. |
| + CanDownload(); |
| + ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, |
| + download_request_limiter_->GetDownloadStatus(web_contents())); |
| + |
| + // Set the content setting to block and send the notification. Ensure that the |
| + // limiter states updates to match. |
| + UpdateContentSettings(web_contents(), CONTENT_SETTING_BLOCK); |
| + ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| + download_request_limiter_->GetDownloadStatus(web_contents())); |
| + |
| + // Check that block to allow works as expected. |
| + UpdateContentSettings(web_contents(), CONTENT_SETTING_ALLOW); |
| + ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS, |
| + download_request_limiter_->GetDownloadStatus(web_contents())); |
| + |
| + // Reset to ask. |
| + UpdateContentSettings(web_contents(), CONTENT_SETTING_ASK); |
| + ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| + download_request_limiter_->GetDownloadStatus(web_contents())); |
| +} |