| OLD | NEW |
| 1 // Copyright (c) 2009 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_infobar_delegate.h" | 5 #include "chrome/browser/download/download_request_infobar_delegate.h" |
| 6 #include "chrome/browser/download/download_request_limiter.h" | 6 #include "chrome/browser/download/download_request_limiter.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 // MockTabDownloadState ------------------------------------------------------- |
| 10 |
| 9 class MockTabDownloadState : public DownloadRequestLimiter::TabDownloadState { | 11 class MockTabDownloadState : public DownloadRequestLimiter::TabDownloadState { |
| 10 public: | 12 public: |
| 11 MockTabDownloadState() : responded_(false), accepted_(false) { | 13 MockTabDownloadState(); |
| 14 virtual ~MockTabDownloadState(); |
| 15 |
| 16 // DownloadRequestLimiter::TabDownloadState |
| 17 virtual void Cancel(); |
| 18 virtual void Accept(); |
| 19 |
| 20 ConfirmInfoBarDelegate* infobar() { |
| 21 return infobar_->AsConfirmInfoBarDelegate(); |
| 12 } | 22 } |
| 13 | 23 bool responded() const { return responded_; } |
| 14 virtual ~MockTabDownloadState() { | 24 bool accepted() const { return accepted_; } |
| 15 EXPECT_TRUE(responded_); | |
| 16 } | |
| 17 | |
| 18 virtual void Accept() { | |
| 19 EXPECT_FALSE(responded_); | |
| 20 responded_ = true; | |
| 21 accepted_ = true; | |
| 22 } | |
| 23 | |
| 24 virtual void Cancel() { | |
| 25 EXPECT_FALSE(responded_); | |
| 26 responded_ = true; | |
| 27 accepted_ = false; | |
| 28 } | |
| 29 | |
| 30 bool responded() { | |
| 31 return responded_; | |
| 32 } | |
| 33 | |
| 34 bool accepted() { | |
| 35 return responded_ && accepted_; | |
| 36 } | |
| 37 | 25 |
| 38 private: | 26 private: |
| 27 // The actual infobar delegate we're listening to. |
| 28 scoped_ptr<InfoBarDelegate> infobar_; |
| 29 |
| 39 // True if we have gotten some sort of response. | 30 // True if we have gotten some sort of response. |
| 40 bool responded_; | 31 bool responded_; |
| 41 | 32 |
| 42 // True if we have gotten a Accept response. Meaningless if |responded_| is | 33 // True if we have gotten a Accept response. Meaningless if |responded_| is |
| 43 // not true. | 34 // not true. |
| 44 bool accepted_; | 35 bool accepted_; |
| 45 }; | 36 }; |
| 46 | 37 |
| 47 TEST(DownloadRequestInfobar, AcceptTest) { | 38 MockTabDownloadState::MockTabDownloadState() |
| 39 : responded_(false), accepted_(false) { |
| 40 infobar_.reset(new DownloadRequestInfoBarDelegate(NULL, this)); |
| 41 } |
| 42 |
| 43 MockTabDownloadState::~MockTabDownloadState() { |
| 44 EXPECT_TRUE(responded_); |
| 45 } |
| 46 |
| 47 void MockTabDownloadState::Cancel() { |
| 48 EXPECT_FALSE(responded_); |
| 49 responded_ = true; |
| 50 accepted_ = false; |
| 51 } |
| 52 |
| 53 void MockTabDownloadState::Accept() { |
| 54 EXPECT_FALSE(responded_); |
| 55 responded_ = true; |
| 56 accepted_ = true; |
| 57 } |
| 58 |
| 59 |
| 60 // Tests ---------------------------------------------------------------------- |
| 61 |
| 62 TEST(DownloadRequestInfobarDelegate, AcceptTest) { |
| 48 MockTabDownloadState state; | 63 MockTabDownloadState state; |
| 49 DownloadRequestInfoBarDelegate infobar(NULL, &state); | 64 state.infobar()->Accept(); |
| 50 infobar.Accept(); | |
| 51 EXPECT_TRUE(state.accepted()); | 65 EXPECT_TRUE(state.accepted()); |
| 52 } | 66 } |
| 53 | 67 |
| 54 TEST(DownloadRequestInfobar, CancelTest) { | 68 TEST(DownloadRequestInfobarDelegate, CancelTest) { |
| 55 MockTabDownloadState state; | 69 MockTabDownloadState state; |
| 56 DownloadRequestInfoBarDelegate infobar(NULL, &state); | 70 state.infobar()->Accept(); |
| 57 infobar.Cancel(); | |
| 58 EXPECT_FALSE(state.accepted()); | 71 EXPECT_FALSE(state.accepted()); |
| 59 } | 72 } |
| 60 | 73 |
| 61 TEST(DownloadRequestInfobar, CloseTest) { | 74 TEST(DownloadRequestInfobarDelegate, CloseTest) { |
| 62 MockTabDownloadState state; | 75 MockTabDownloadState state; |
| 63 DownloadRequestInfoBarDelegate infobar(NULL, &state); | 76 state.infobar()->InfoBarClosed(); |
| 64 infobar.InfoBarClosed(); | |
| 65 EXPECT_FALSE(state.accepted()); | 77 EXPECT_FALSE(state.accepted()); |
| 66 } | 78 } |
| OLD | NEW |