| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/test/testing_profile.h" | 7 #include "chrome/test/testing_profile.h" |
| 7 #include "content/browser/browser_thread.h" | 8 #include "content/browser/browser_thread.h" |
| 8 #include "content/browser/renderer_host/test_render_view_host.h" | |
| 9 #include "content/browser/tab_contents/navigation_controller.h" | 9 #include "content/browser/tab_contents/navigation_controller.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 class DownloadRequestLimiterTest | 12 class DownloadRequestLimiterTest |
| 13 : public RenderViewHostTestHarness, | 13 : public TabContentsWrapperTestHarness, |
| 14 public DownloadRequestLimiter::Callback { | 14 public DownloadRequestLimiter::Callback { |
| 15 public: | 15 public: |
| 16 DownloadRequestLimiterTest() : io_thread_(BrowserThread::IO, &message_loop_) { | 16 DownloadRequestLimiterTest() : io_thread_(BrowserThread::IO, &message_loop_) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 virtual void SetUp() { | 19 virtual void SetUp() { |
| 20 RenderViewHostTestHarness::SetUp(); | 20 TabContentsWrapperTestHarness::SetUp(); |
| 21 | 21 |
| 22 allow_download_ = true; | 22 allow_download_ = true; |
| 23 ask_allow_count_ = cancel_count_ = continue_count_ = 0; | 23 ask_allow_count_ = cancel_count_ = continue_count_ = 0; |
| 24 | 24 |
| 25 download_request_limiter_ = new DownloadRequestLimiter(); | 25 download_request_limiter_ = new DownloadRequestLimiter(); |
| 26 test_delegate_.reset(new DownloadRequestLimiterTestDelegate(this)); | 26 test_delegate_.reset(new DownloadRequestLimiterTestDelegate(this)); |
| 27 DownloadRequestLimiter::SetTestingDelegate(test_delegate_.get()); | 27 DownloadRequestLimiter::SetTestingDelegate(test_delegate_.get()); |
| 28 } | 28 } |
| 29 | 29 |
| 30 virtual void TearDown() { | 30 virtual void TearDown() { |
| 31 DownloadRequestLimiter::SetTestingDelegate(NULL); | 31 DownloadRequestLimiter::SetTestingDelegate(NULL); |
| 32 | 32 |
| 33 RenderViewHostTestHarness::TearDown(); | 33 TabContentsWrapperTestHarness::TearDown(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 virtual void ContinueDownload() { | 36 virtual void ContinueDownload() { |
| 37 continue_count_++; | 37 continue_count_++; |
| 38 } | 38 } |
| 39 virtual void CancelDownload() { | 39 virtual void CancelDownload() { |
| 40 cancel_count_++; | 40 cancel_count_++; |
| 41 } | 41 } |
| 42 | 42 |
| 43 void CanDownload() { | 43 void CanDownload() { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 ask_allow_count_ = continue_count_ = cancel_count_ = 0; | 201 ask_allow_count_ = continue_count_ = cancel_count_ = 0; |
| 202 CanDownload(); | 202 CanDownload(); |
| 203 ASSERT_EQ(0, ask_allow_count_); | 203 ASSERT_EQ(0, ask_allow_count_); |
| 204 ASSERT_EQ(0, continue_count_); | 204 ASSERT_EQ(0, continue_count_); |
| 205 ASSERT_EQ(1, cancel_count_); | 205 ASSERT_EQ(1, cancel_count_); |
| 206 // And the state shouldn't have changed. | 206 // And the state shouldn't have changed. |
| 207 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 207 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 208 download_request_limiter_->GetDownloadStatus( | 208 download_request_limiter_->GetDownloadStatus( |
| 209 controller().tab_contents())); | 209 controller().tab_contents())); |
| 210 } | 210 } |
| OLD | NEW |