OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/download/download_request_infobar_delegate.h" |
| 6 #include "chrome/browser/download/download_request_manager.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 class MockTabDownloadState : public DownloadRequestManager::TabDownloadState { |
| 10 public: |
| 11 MockTabDownloadState() : responded_(false), accepted_(false) { |
| 12 } |
| 13 |
| 14 virtual ~MockTabDownloadState() { |
| 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 |
| 38 private: |
| 39 // True if we have gotten some sort of response. |
| 40 bool responded_; |
| 41 |
| 42 // True if we have gotten a Accept response. Meaningless if |responded_| is |
| 43 // not true. |
| 44 bool accepted_; |
| 45 }; |
| 46 |
| 47 TEST(DownloadRequestInfobar, AcceptTest) { |
| 48 MockTabDownloadState state; |
| 49 DownloadRequestInfoBarDelegate infobar(NULL, &state); |
| 50 infobar.Accept(); |
| 51 EXPECT_TRUE(state.accepted()); |
| 52 } |
| 53 |
| 54 TEST(DownloadRequestInfobar, CancelTest) { |
| 55 MockTabDownloadState state; |
| 56 DownloadRequestInfoBarDelegate infobar(NULL, &state); |
| 57 infobar.Cancel(); |
| 58 EXPECT_FALSE(state.accepted()); |
| 59 } |
| 60 |
| 61 TEST(DownloadRequestInfobar, CloseTest) { |
| 62 MockTabDownloadState state; |
| 63 DownloadRequestInfoBarDelegate infobar(NULL, &state); |
| 64 infobar.InfoBarClosed(); |
| 65 EXPECT_FALSE(state.accepted()); |
| 66 } |
OLD | NEW |