Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Unified Diff: chrome/browser/download/download_request_limiter_unittest.cc

Issue 1675533002: Make the download request limiter listen to content settings changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address reviewer comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/download/download_request_limiter.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f153cf426e2ced0683bcf8cc8a7f216c8418e7a7 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"
@@ -154,7 +157,7 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness {
void TearDown() override {
content_settings_->ShutdownOnUIThread();
- content_settings_ = NULL;
+ content_settings_ = nullptr;
testing_delegate_.TearDown();
ChromeRenderViewHostTestHarness::TearDown();
}
@@ -178,7 +181,8 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness {
void OnUserGestureFor(WebContents* web_contents) {
DownloadRequestLimiter::TabDownloadState* state =
- download_request_limiter_->GetDownloadState(web_contents, NULL, false);
+ download_request_limiter_->GetDownloadState(web_contents, nullptr,
+ false);
if (state)
state->DidGetUserGesture();
}
@@ -195,6 +199,20 @@ 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, nullptr, true);
+ SetHostContentSetting(web_contents, setting);
+
+ // Manually send the update notification. In the browser, this is sent from
+ // ContentSettingRPHBubbleModel.
+ 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 +503,59 @@ TEST_F(DownloadRequestLimiterTest,
ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
download_request_limiter_->GetDownloadStatus(web_contents()));
}
+
+TEST_F(DownloadRequestLimiterTest,
+ DownloadRequestLimiter_ContentSettingChanged) {
+ NavigateAndCommit(GURL("http://foo.com/bar"));
+ LoadCompleted();
+ ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+
+ CanDownload();
+ ExpectAndResetCounts(1, 0, 0, __LINE__);
+ ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+
+ // Simulate an accidental deny.
+ UpdateExpectations(CANCEL);
+ CanDownload();
+ ExpectAndResetCounts(0, 1, 1, __LINE__);
+ ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED,
+ 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 that it succeeded and we are still in allow.
+ CanDownload();
+ ExpectAndResetCounts(1, 0, 0, __LINE__);
+ 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()));
+
+ // Ensure downloads are blocked.
+ CanDownload();
+ ExpectAndResetCounts(0, 1, 0, __LINE__);
+ ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+
+ // Reset to ask. Verify that the download counts have not changed on the
+ // content settings change (ensuring there is no "free" download after
+ // changing the content setting).
+ UpdateContentSettings(web_contents(), CONTENT_SETTING_ASK);
+ ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+ UpdateExpectations(WAIT);
+ CanDownload();
+ ExpectAndResetCounts(0, 0, 1, __LINE__);
+ ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+}
« no previous file with comments | « chrome/browser/download/download_request_limiter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698