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

Side by Side Diff: chrome/browser/download/download_request_limiter_unittest.cc

Issue 2561673003: Handle per-tab AUTOMATIC_DOWNLOADS setting in DownloadRequestLimiter. (Closed)
Patch Set: Handle per-tab AUTOMATIC_DOWNLOADS setting in DownloadRequestLimiter. Created 3 years, 11 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 unified diff | Download patch
OLDNEW
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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 EXPECT_EQ(expect_asks, AskAllowCount()) << "line " << line; 205 EXPECT_EQ(expect_asks, AskAllowCount()) << "line " << line;
206 continue_count_ = cancel_count_ = 0; 206 continue_count_ = cancel_count_ = 0;
207 testing_delegate_.ResetCounts(); 207 testing_delegate_.ResetCounts();
208 } 208 }
209 209
210 void UpdateContentSettings(WebContents* web_contents, 210 void UpdateContentSettings(WebContents* web_contents,
211 ContentSetting setting) { 211 ContentSetting setting) {
212 // Ensure a download state exists. 212 // Ensure a download state exists.
213 download_request_limiter_->GetDownloadState(web_contents, nullptr, true); 213 download_request_limiter_->GetDownloadState(web_contents, nullptr, true);
214 SetHostContentSetting(web_contents, setting); 214 SetHostContentSetting(web_contents, setting);
215
216 // Manually send the update notification. In the browser, this is sent from
217 // ContentSettingRPHBubbleModel.
218 content::NotificationService::current()->Notify(
219 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
220 content::Source<WebContents>(web_contents),
221 content::NotificationService::NoDetails());
222 } 215 }
223 216
224 protected: 217 protected:
225 void ContinueDownload(bool allow) { 218 void ContinueDownload(bool allow) {
226 if (allow) { 219 if (allow) {
227 continue_count_++; 220 continue_count_++;
228 } else { 221 } else {
229 cancel_count_++; 222 cancel_count_++;
230 } 223 }
231 } 224 }
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 LoadCompleted(); 636 LoadCompleted();
644 SetHostContentSetting(web_contents(), CONTENT_SETTING_ALLOW); 637 SetHostContentSetting(web_contents(), CONTENT_SETTING_ALLOW);
645 638
646 CanDownload(); 639 CanDownload();
647 ExpectAndResetCounts(1, 0, 0, __LINE__); 640 ExpectAndResetCounts(1, 0, 0, __LINE__);
648 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, 641 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
649 download_request_limiter_->GetDownloadStatus(web_contents())); 642 download_request_limiter_->GetDownloadStatus(web_contents()));
650 643
651 CanDownload(); 644 CanDownload();
652 ExpectAndResetCounts(1, 0, 0, __LINE__); 645 ExpectAndResetCounts(1, 0, 0, __LINE__);
653 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, 646 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS,
654 download_request_limiter_->GetDownloadStatus(web_contents())); 647 download_request_limiter_->GetDownloadStatus(web_contents()));
655 648
656 SetHostContentSetting(web_contents(), CONTENT_SETTING_BLOCK); 649 SetHostContentSetting(web_contents(), CONTENT_SETTING_BLOCK);
657 650
658 CanDownload(); 651 CanDownload();
659 ExpectAndResetCounts(0, 1, 0, __LINE__); 652 ExpectAndResetCounts(0, 1, 0, __LINE__);
660 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, 653 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED,
661 download_request_limiter_->GetDownloadStatus(web_contents())); 654 download_request_limiter_->GetDownloadStatus(web_contents()));
662 655
663 CanDownload(); 656 CanDownload();
664 ExpectAndResetCounts(0, 1, 0, __LINE__); 657 ExpectAndResetCounts(0, 1, 0, __LINE__);
665 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, 658 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED,
666 download_request_limiter_->GetDownloadStatus(web_contents())); 659 download_request_limiter_->GetDownloadStatus(web_contents()));
667 } 660 }
668 661
669 TEST_F(DownloadRequestLimiterTest, 662 TEST_F(DownloadRequestLimiterTest,
670 DownloadRequestLimiter_ContentSettingChanged) { 663 DownloadRequestLimiter_ContentSettingChanged) {
671 NavigateAndCommit(GURL("http://foo.com/bar")); 664 NavigateAndCommit(GURL("http://foo.com/bar"));
672 LoadCompleted(); 665 LoadCompleted();
673 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, 666 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD,
674 download_request_limiter_->GetDownloadStatus(web_contents())); 667 download_request_limiter_->GetDownloadStatus(web_contents()));
675 668
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 // changing the content setting). 707 // changing the content setting).
715 UpdateContentSettings(web_contents(), CONTENT_SETTING_ASK); 708 UpdateContentSettings(web_contents(), CONTENT_SETTING_ASK);
716 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, 709 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
717 download_request_limiter_->GetDownloadStatus(web_contents())); 710 download_request_limiter_->GetDownloadStatus(web_contents()));
718 UpdateExpectations(WAIT); 711 UpdateExpectations(WAIT);
719 CanDownload(); 712 CanDownload();
720 ExpectAndResetCounts(0, 0, 1, __LINE__); 713 ExpectAndResetCounts(0, 0, 1, __LINE__);
721 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, 714 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
722 download_request_limiter_->GetDownloadStatus(web_contents())); 715 download_request_limiter_->GetDownloadStatus(web_contents()));
723 } 716 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698