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

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

Issue 1086733002: Ensure tests have an active task runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 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 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 "chrome/browser/download/download_permission_request.h" 10 #include "chrome/browser/download/download_permission_request.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness { 59 class DownloadRequestLimiterTest : public ChromeRenderViewHostTestHarness {
60 public: 60 public:
61 enum TestingAction { 61 enum TestingAction {
62 ACCEPT, 62 ACCEPT,
63 CANCEL, 63 CANCEL,
64 WAIT 64 WAIT
65 }; 65 };
66 66
67 void SetUp() override { 67 void SetUp() override {
68 ChromeRenderViewHostTestHarness::SetUp(); 68 ChromeRenderViewHostTestHarness::SetUp();
69 profile_.reset(new TestingProfile());
69 InfoBarService::CreateForWebContents(web_contents()); 70 InfoBarService::CreateForWebContents(web_contents());
70 71
71 PermissionBubbleManager::CreateForWebContents(web_contents()); 72 PermissionBubbleManager::CreateForWebContents(web_contents());
72 view_.reset(new FakePermissionBubbleView(this)); 73 view_.reset(new FakePermissionBubbleView(this));
73 PermissionBubbleManager::FromWebContents(web_contents())-> 74 PermissionBubbleManager::FromWebContents(web_contents())->
74 SetView(view_.get()); 75 SetView(view_.get());
75 76
76 testing_action_ = ACCEPT; 77 testing_action_ = ACCEPT;
77 ask_allow_count_ = cancel_count_ = continue_count_ = 0; 78 ask_allow_count_ = cancel_count_ = continue_count_ = 0;
78 download_request_limiter_ = new DownloadRequestLimiter(); 79 download_request_limiter_ = new DownloadRequestLimiter();
79 fake_create_callback_ = base::Bind( 80 fake_create_callback_ = base::Bind(
80 &DownloadRequestLimiterTest::FakeCreate, base::Unretained(this)); 81 &DownloadRequestLimiterTest::FakeCreate, base::Unretained(this));
81 DownloadRequestInfoBarDelegate::SetCallbackForTesting( 82 DownloadRequestInfoBarDelegate::SetCallbackForTesting(
82 &fake_create_callback_); 83 &fake_create_callback_);
83 content_settings_ = new HostContentSettingsMap(profile_.GetPrefs(), false); 84 content_settings_ = new HostContentSettingsMap(profile_->GetPrefs(), false);
84 DownloadRequestLimiter::SetContentSettingsForTesting( 85 DownloadRequestLimiter::SetContentSettingsForTesting(
85 content_settings_.get()); 86 content_settings_.get());
86 } 87 }
87 88
88 int GetAction() { 89 int GetAction() {
89 return testing_action_; 90 return testing_action_;
90 } 91 }
91 92
92 void AskAllow() { 93 void AskAllow() {
93 ask_allow_count_++; 94 ask_allow_count_++;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // Number of times CancelDownload was invoked. 192 // Number of times CancelDownload was invoked.
192 int cancel_count_; 193 int cancel_count_;
193 194
194 // Number of times ShouldAllowDownload was invoked. 195 // Number of times ShouldAllowDownload was invoked.
195 int ask_allow_count_; 196 int ask_allow_count_;
196 197
197 scoped_refptr<HostContentSettingsMap> content_settings_; 198 scoped_refptr<HostContentSettingsMap> content_settings_;
198 199
199 private: 200 private:
200 DownloadRequestInfoBarDelegate::FakeCreateCallback fake_create_callback_; 201 DownloadRequestInfoBarDelegate::FakeCreateCallback fake_create_callback_;
201 TestingProfile profile_; 202 scoped_ptr<TestingProfile> profile_;
202 scoped_ptr<FakePermissionBubbleView> view_; 203 scoped_ptr<FakePermissionBubbleView> view_;
203 }; 204 };
204 205
205 void FakePermissionBubbleView::Show( 206 void FakePermissionBubbleView::Show(
206 const std::vector<PermissionBubbleRequest*>& requests, 207 const std::vector<PermissionBubbleRequest*>& requests,
207 const std::vector<bool>& accept_state) { 208 const std::vector<bool>& accept_state) {
208 test_->AskAllow(); 209 test_->AskAllow();
209 int action = test_->GetAction(); 210 int action = test_->GetAction();
210 if (action == DownloadRequestLimiterTest::ACCEPT) { 211 if (action == DownloadRequestLimiterTest::ACCEPT) {
211 delegate_->Accept(); 212 delegate_->Accept();
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 500
500 CanDownload(); 501 CanDownload();
501 ExpectAndResetCounts(0, 1, 0, __LINE__); 502 ExpectAndResetCounts(0, 1, 0, __LINE__);
502 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, 503 ASSERT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD,
503 download_request_limiter_->GetDownloadStatus(web_contents())); 504 download_request_limiter_->GetDownloadStatus(web_contents()));
504 } 505 }
505 506
506 INSTANTIATE_TEST_CASE_P(DownloadRequestLimiterTestsWithAndWithoutBubbles, 507 INSTANTIATE_TEST_CASE_P(DownloadRequestLimiterTestsWithAndWithoutBubbles,
507 DownloadRequestLimiterParamTests, 508 DownloadRequestLimiterParamTests,
508 ::testing::Values(false, true)); 509 ::testing::Values(false, true));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698