| 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 "chrome/browser/download/download_request_limiter.h" | 5 #include "chrome/browser/download/download_request_limiter.h" |
| 6 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 6 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
| 7 #include "chrome/test/base/testing_profile.h" | 7 #include "chrome/test/base/testing_profile.h" |
| 8 #include "content/browser/tab_contents/test_tab_contents.h" | 8 #include "content/browser/tab_contents/test_tab_contents.h" |
| 9 #include "content/public/browser/navigation_controller.h" | 9 #include "content/public/browser/navigation_controller.h" |
| 10 #include "content/test/test_browser_thread.h" | 10 #include "content/test/test_browser_thread.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 using content::BrowserThread; | 13 using content::BrowserThread; |
| 14 | 14 |
| 15 class DownloadRequestLimiterTest : public TabContentsWrapperTestHarness { | 15 class DownloadRequestLimiterTest : public TabContentsWrapperTestHarness { |
| 16 public: | 16 public: |
| 17 DownloadRequestLimiterTest() | 17 DownloadRequestLimiterTest() |
| 18 : ui_thread_(BrowserThread::UI, &message_loop_), | 18 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 19 file_user_blocking_thread_( |
| 20 BrowserThread::FILE_USER_BLOCKING, &message_loop_), |
| 19 io_thread_(BrowserThread::IO, &message_loop_) { | 21 io_thread_(BrowserThread::IO, &message_loop_) { |
| 20 } | 22 } |
| 21 | 23 |
| 22 virtual void SetUp() { | 24 virtual void SetUp() { |
| 23 TabContentsWrapperTestHarness::SetUp(); | 25 TabContentsWrapperTestHarness::SetUp(); |
| 24 | 26 |
| 25 allow_download_ = true; | 27 allow_download_ = true; |
| 26 ask_allow_count_ = cancel_count_ = continue_count_ = 0; | 28 ask_allow_count_ = cancel_count_ = continue_count_ = 0; |
| 27 | 29 |
| 28 download_request_limiter_ = new DownloadRequestLimiter(); | 30 download_request_limiter_ = new DownloadRequestLimiter(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // Number of times CancelDownload was invoked. | 85 // Number of times CancelDownload was invoked. |
| 84 int cancel_count_; | 86 int cancel_count_; |
| 85 | 87 |
| 86 // Whether the download should be allowed. | 88 // Whether the download should be allowed. |
| 87 bool allow_download_; | 89 bool allow_download_; |
| 88 | 90 |
| 89 // Number of times ShouldAllowDownload was invoked. | 91 // Number of times ShouldAllowDownload was invoked. |
| 90 int ask_allow_count_; | 92 int ask_allow_count_; |
| 91 | 93 |
| 92 content::TestBrowserThread ui_thread_; | 94 content::TestBrowserThread ui_thread_; |
| 95 content::TestBrowserThread file_user_blocking_thread_; |
| 93 content::TestBrowserThread io_thread_; | 96 content::TestBrowserThread io_thread_; |
| 94 }; | 97 }; |
| 95 | 98 |
| 96 TEST_F(DownloadRequestLimiterTest, Allow) { | 99 TEST_F(DownloadRequestLimiterTest, Allow) { |
| 97 // All tabs should initially start at ALLOW_ONE_DOWNLOAD. | 100 // All tabs should initially start at ALLOW_ONE_DOWNLOAD. |
| 98 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 101 ASSERT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
| 99 download_request_limiter_->GetDownloadStatus(contents())); | 102 download_request_limiter_->GetDownloadStatus(contents())); |
| 100 | 103 |
| 101 // Ask if the tab can do a download. This moves to PROMPT_BEFORE_DOWNLOAD. | 104 // Ask if the tab can do a download. This moves to PROMPT_BEFORE_DOWNLOAD. |
| 102 CanDownload(); | 105 CanDownload(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // And make sure we really can't download. | 199 // And make sure we really can't download. |
| 197 ask_allow_count_ = continue_count_ = cancel_count_ = 0; | 200 ask_allow_count_ = continue_count_ = cancel_count_ = 0; |
| 198 CanDownload(); | 201 CanDownload(); |
| 199 ASSERT_EQ(0, ask_allow_count_); | 202 ASSERT_EQ(0, ask_allow_count_); |
| 200 ASSERT_EQ(0, continue_count_); | 203 ASSERT_EQ(0, continue_count_); |
| 201 ASSERT_EQ(1, cancel_count_); | 204 ASSERT_EQ(1, cancel_count_); |
| 202 // And the state shouldn't have changed. | 205 // And the state shouldn't have changed. |
| 203 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 206 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 204 download_request_limiter_->GetDownloadStatus(contents())); | 207 download_request_limiter_->GetDownloadStatus(contents())); |
| 205 } | 208 } |
| OLD | NEW |