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

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

Issue 1964863002: Persist prompt/block download limiter state on renderer-initiated loads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implement DidFinishNavigation Created 4 years, 7 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
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 e5c3e4569cd5bc0a9f206df1180db3c2fb0573fe..ae27609eff61e75be5158e168b4cb37c97fdf07a 100644
--- a/chrome/browser/download/download_request_limiter_unittest.cc
+++ b/chrome/browser/download/download_request_limiter_unittest.cc
@@ -18,6 +18,7 @@
#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/browser_side_navigation_policy.h"
#include "content/public/common/frame_navigate_params.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -344,6 +345,90 @@ TEST_F(DownloadRequestLimiterTest, DownloadRequestLimiter_ResetOnNavigation) {
download_request_limiter_->GetDownloadStatus(web_contents()));
}
+TEST_F(DownloadRequestLimiterTest, DownloadRequestLimiter_RendererInitiated) {
+ // This test will only work when browser-side navigation enabled, as the
+ // renderer initiated navigation check will always return false otherwise.
+ if (content::IsBrowserSideNavigationEnabled()) {
+ NavigateAndCommit(GURL("http://foo.com/bar"));
+ LoadCompleted();
+
+ // Do one download so we end up in PROMPT.
+ CanDownload();
+ ExpectAndResetCounts(1, 0, 0, __LINE__);
+ ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+
+ // Set up a pending renderer-initiated download to the same host.
+ content::NavigationController::LoadURLParams load_params(
+ GURL("http://foo.com/bar2"));
+ load_params.is_renderer_initiated = true;
+ load_params.transition_type = ui::PAGE_TRANSITION_GENERATED;
+ load_params.referrer = content::Referrer();
+ controller().LoadURLWithParams(load_params);
+
+ // The state should not be reset.
+ ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+
+ // Pending renderer-initiated navigation to a different host should not
+ // reset the state.
+ load_params.url = GURL("http://fooey.com/bar");
+ ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+
+ // Set up a blocked state.
+ UpdateExpectations(CANCEL);
+ CanDownload();
+ ExpectAndResetCounts(0, 1, 1, __LINE__);
+ ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+
+ // The state should not be reset on a pending renderer-initiated load to
+ // either the same host or a different host.
+ load_params.url = GURL("http://fooeybar.com/bar");
+ controller().LoadURLWithParams(load_params);
+ ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+
+ load_params.url = GURL("http://foo.com/bar");
+ controller().LoadURLWithParams(load_params);
+ ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+
+ // Browser-initiated navigation to a different host, which should reset the
+ // state.
+ NavigateAndCommit(GURL("http://foobar.com"));
+ LoadCompleted();
+ ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+
+ // Set up an allow all state.
+ CanDownload();
+ ExpectAndResetCounts(1, 0, 0, __LINE__);
+ ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+
+ UpdateExpectations(ACCEPT);
+ CanDownload();
+ ExpectAndResetCounts(1, 0, 1, __LINE__);
+ ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+
+ // The state should not be reset on a pending renderer-initiated load to
+ // the same host.
+ load_params.url = GURL("http://foobar.com/bar");
+ controller().LoadURLWithParams(load_params);
+ ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+
+ // But a pending load to a different host should reset the state.
+ load_params.url = GURL("http://foo.com");
+ controller().LoadURLWithParams(load_params);
+ ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD,
+ download_request_limiter_->GetDownloadStatus(web_contents()));
+ }
+}
+
TEST_F(DownloadRequestLimiterTest, DownloadRequestLimiter_ResetOnUserGesture) {
NavigateAndCommit(GURL("http://foo.com/bar"));
LoadCompleted();

Powered by Google App Engine
This is Rietveld 408576698