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

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

Issue 2561673003: Handle per-tab AUTOMATIC_DOWNLOADS setting in DownloadRequestLimiter. (Closed)
Patch Set: Get HostContentSettingsMap directly in DRL tests Created 3 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
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 14d15026609ad3aeacccf0acd276e31848ee1a05..82a5940dba4ae904e606bf91abef8cd35a71ef8b 100644
--- a/chrome/browser/download/download_request_limiter_unittest.cc
+++ b/chrome/browser/download/download_request_limiter_unittest.cc
@@ -9,9 +9,10 @@
#include "base/run_loop.h"
#include "build/build_config.h"
#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
+#include "chrome/browser/profiles/profile.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"
@@ -143,29 +144,16 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness {
public:
void SetUp() override {
ChromeRenderViewHostTestHarness::SetUp();
- profile_.reset(new TestingProfile());
testing_delegate_.SetUp(web_contents());
UpdateExpectations(ACCEPT);
cancel_count_ = continue_count_ = 0;
download_request_limiter_ = new DownloadRequestLimiter();
-
- content_settings_ = new HostContentSettingsMap(
- profile_->GetPrefs(), false /* incognito_profile */,
- false /* guest_profile */);
- DownloadRequestLimiter::SetContentSettingsForTesting(
- content_settings_.get());
}
void TearDown() override {
- content_settings_->ShutdownOnUIThread();
- content_settings_ = nullptr;
testing_delegate_.TearDown();
- // |profile_| must be teared down before
- // |RenderViewHostTestHarness::thread_bundle_|.
- profile_.reset();
-
ChromeRenderViewHostTestHarness::TearDown();
}
@@ -212,13 +200,6 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness {
// 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:
@@ -231,9 +212,11 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness {
}
void SetHostContentSetting(WebContents* contents, ContentSetting setting) {
- content_settings_->SetContentSettingDefaultScope(
- contents->GetURL(), GURL(), CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
- std::string(), setting);
+ HostContentSettingsMapFactory::GetForProfile(
+ Profile::FromBrowserContext(contents->GetBrowserContext()))
+ ->SetContentSettingDefaultScope(
+ contents->GetURL(), GURL(),
+ CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(), setting);
}
void LoadCompleted() { testing_delegate_.LoadCompleted(web_contents()); }
@@ -252,11 +235,7 @@ class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness {
// Number of times CancelDownload was invoked.
int cancel_count_;
- scoped_refptr<HostContentSettingsMap> content_settings_;
TestingDelegate testing_delegate_;
-
- private:
- std::unique_ptr<TestingProfile> profile_;
};
TEST_F(DownloadRequestLimiterTest, DownloadRequestLimiter_Allow) {
@@ -650,19 +629,19 @@ TEST_F(DownloadRequestLimiterTest,
CanDownload();
ExpectAndResetCounts(1, 0, 0, __LINE__);
- ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
+ ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS,
download_request_limiter_->GetDownloadStatus(web_contents()));
SetHostContentSetting(web_contents(), CONTENT_SETTING_BLOCK);
CanDownload();
ExpectAndResetCounts(0, 1, 0, __LINE__);
- ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
+ ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED,
download_request_limiter_->GetDownloadStatus(web_contents()));
CanDownload();
ExpectAndResetCounts(0, 1, 0, __LINE__);
- ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
+ ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED,
download_request_limiter_->GetDownloadStatus(web_contents()));
}

Powered by Google App Engine
This is Rietveld 408576698