OLD | NEW |
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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "chrome/browser/download/download_request_limiter.h" | 6 #include "chrome/browser/download/download_request_limiter.h" |
7 #include "chrome/browser/infobars/infobar_tab_helper.h" | 7 #include "chrome/browser/infobars/infobar_tab_helper.h" |
8 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" | 8 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 CanDownloadFor(web_contents()); | 51 CanDownloadFor(web_contents()); |
52 } | 52 } |
53 | 53 |
54 void CanDownloadFor(WebContents* web_contents) { | 54 void CanDownloadFor(WebContents* web_contents) { |
55 download_request_limiter_->CanDownloadImpl( | 55 download_request_limiter_->CanDownloadImpl( |
56 web_contents, | 56 web_contents, |
57 -1, // request id | 57 -1, // request id |
58 "GET", // request method | 58 "GET", // request method |
59 base::Bind(&DownloadRequestLimiterTest::ContinueDownload, | 59 base::Bind(&DownloadRequestLimiterTest::ContinueDownload, |
60 base::Unretained(this))); | 60 base::Unretained(this))); |
61 message_loop_.RunAllPending(); | 61 message_loop_.RunUntilIdle(); |
62 } | 62 } |
63 | 63 |
64 void OnUserGesture() { | 64 void OnUserGesture() { |
65 OnUserGestureFor(web_contents()); | 65 OnUserGestureFor(web_contents()); |
66 } | 66 } |
67 | 67 |
68 void OnUserGestureFor(WebContents* web_contents) { | 68 void OnUserGestureFor(WebContents* web_contents) { |
69 DownloadRequestLimiter::TabDownloadState* state = | 69 DownloadRequestLimiter::TabDownloadState* state = |
70 download_request_limiter_->GetDownloadState(web_contents, NULL, false); | 70 download_request_limiter_->GetDownloadState(web_contents, NULL, false); |
71 if (state) | 71 if (state) |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 267 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
268 OnUserGestureFor(web_contents.get()); | 268 OnUserGestureFor(web_contents.get()); |
269 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 269 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
270 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 270 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
271 CanDownloadFor(web_contents.get()); | 271 CanDownloadFor(web_contents.get()); |
272 EXPECT_EQ(3, continue_count_); | 272 EXPECT_EQ(3, continue_count_); |
273 EXPECT_EQ(1, cancel_count_); | 273 EXPECT_EQ(1, cancel_count_); |
274 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 274 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
275 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 275 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
276 } | 276 } |
OLD | NEW |