| 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/ui/tab_contents/tab_contents_wrapper.h" | 7 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 8 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 8 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" |
| 9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
| 10 #include "content/public/browser/navigation_controller.h" | 10 #include "content/public/browser/navigation_controller.h" |
| 11 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
| 12 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 using content::BrowserThread; | 15 using content::BrowserThread; |
| 16 using content::WebContents; | 16 using content::WebContents; |
| 17 | 17 |
| 18 class DownloadRequestLimiterTest : public TabContentsWrapperTestHarness { | 18 class DownloadRequestLimiterTest : public TabContentsTestHarness { |
| 19 public: | 19 public: |
| 20 DownloadRequestLimiterTest() | 20 DownloadRequestLimiterTest() |
| 21 : ui_thread_(BrowserThread::UI, &message_loop_), | 21 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 22 file_user_blocking_thread_( | 22 file_user_blocking_thread_( |
| 23 BrowserThread::FILE_USER_BLOCKING, &message_loop_), | 23 BrowserThread::FILE_USER_BLOCKING, &message_loop_), |
| 24 io_thread_(BrowserThread::IO, &message_loop_) { | 24 io_thread_(BrowserThread::IO, &message_loop_) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 virtual void SetUp() { | 27 virtual void SetUp() { |
| 28 TabContentsWrapperTestHarness::SetUp(); | 28 TabContentsTestHarness::SetUp(); |
| 29 | 29 |
| 30 allow_download_ = true; | 30 allow_download_ = true; |
| 31 ask_allow_count_ = cancel_count_ = continue_count_ = 0; | 31 ask_allow_count_ = cancel_count_ = continue_count_ = 0; |
| 32 | 32 |
| 33 download_request_limiter_ = new DownloadRequestLimiter(); | 33 download_request_limiter_ = new DownloadRequestLimiter(); |
| 34 test_delegate_.reset(new DownloadRequestLimiterTestDelegate(this)); | 34 test_delegate_.reset(new DownloadRequestLimiterTestDelegate(this)); |
| 35 DownloadRequestLimiter::SetTestingDelegate(test_delegate_.get()); | 35 DownloadRequestLimiter::SetTestingDelegate(test_delegate_.get()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 virtual void TearDown() { | 38 virtual void TearDown() { |
| 39 UnsetDelegate(); | 39 UnsetDelegate(); |
| 40 TabContentsWrapperTestHarness::TearDown(); | 40 TabContentsTestHarness::TearDown(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 virtual void UnsetDelegate() { | 43 virtual void UnsetDelegate() { |
| 44 DownloadRequestLimiter::SetTestingDelegate(NULL); | 44 DownloadRequestLimiter::SetTestingDelegate(NULL); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void CanDownload() { | 47 void CanDownload() { |
| 48 CanDownloadFor(web_contents()); | 48 CanDownloadFor(web_contents()); |
| 49 } | 49 } |
| 50 | 50 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 ASSERT_EQ(0, ask_allow_count_); | 227 ASSERT_EQ(0, ask_allow_count_); |
| 228 ASSERT_EQ(0, continue_count_); | 228 ASSERT_EQ(0, continue_count_); |
| 229 ASSERT_EQ(1, cancel_count_); | 229 ASSERT_EQ(1, cancel_count_); |
| 230 // And the state shouldn't have changed. | 230 // And the state shouldn't have changed. |
| 231 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, | 231 ASSERT_EQ(DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED, |
| 232 download_request_limiter_->GetDownloadStatus(contents())); | 232 download_request_limiter_->GetDownloadStatus(contents())); |
| 233 } | 233 } |
| 234 | 234 |
| 235 TEST_F(DownloadRequestLimiterTest, | 235 TEST_F(DownloadRequestLimiterTest, |
| 236 DownloadRequestLimiter_RawWebContents) { | 236 DownloadRequestLimiter_RawWebContents) { |
| 237 // By-pass TabContentsWrapperTestHarness and use | 237 // By-pass TabContentsTestHarness and use |
| 238 // RenderViewHostTestHarness::CreateTestWebContents() directly so that there | 238 // RenderViewHostTestHarness::CreateTestWebContents() directly so that there |
| 239 // will be no TabContentsWrapper for web_contents. | 239 // will be no TabContentsWrapper for web_contents. |
| 240 scoped_ptr<WebContents> web_contents(CreateTestWebContents()); | 240 scoped_ptr<WebContents> web_contents(CreateTestWebContents()); |
| 241 TabContentsWrapper* tab_wrapper = | 241 TabContentsWrapper* tab_wrapper = |
| 242 TabContentsWrapper::GetCurrentWrapperForContents(web_contents.get()); | 242 TabContentsWrapper::GetCurrentWrapperForContents(web_contents.get()); |
| 243 ASSERT_TRUE(tab_wrapper == NULL); | 243 ASSERT_TRUE(tab_wrapper == NULL); |
| 244 // DRL won't try to make an infobar if it doesn't have a TCW, and we want to | 244 // DRL won't try to make an infobar if it doesn't have a TCW, and we want to |
| 245 // test that it will Cancel() instead of prompting when it doesn't have a TCW, | 245 // test that it will Cancel() instead of prompting when it doesn't have a TCW, |
| 246 // so unset the delegate. | 246 // so unset the delegate. |
| 247 UnsetDelegate(); | 247 UnsetDelegate(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 270 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 270 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
| 271 OnUserGestureFor(web_contents.get()); | 271 OnUserGestureFor(web_contents.get()); |
| 272 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, | 272 EXPECT_EQ(DownloadRequestLimiter::ALLOW_ONE_DOWNLOAD, |
| 273 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 273 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
| 274 CanDownloadFor(web_contents.get()); | 274 CanDownloadFor(web_contents.get()); |
| 275 EXPECT_EQ(3, continue_count_); | 275 EXPECT_EQ(3, continue_count_); |
| 276 EXPECT_EQ(1, cancel_count_); | 276 EXPECT_EQ(1, cancel_count_); |
| 277 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, | 277 EXPECT_EQ(DownloadRequestLimiter::PROMPT_BEFORE_DOWNLOAD, |
| 278 download_request_limiter_->GetDownloadStatus(web_contents.get())); | 278 download_request_limiter_->GetDownloadStatus(web_contents.get())); |
| 279 } | 279 } |
| OLD | NEW |