Index: chrome/browser/download/download_request_infobar_delegate_unittest.cc |
=================================================================== |
--- chrome/browser/download/download_request_infobar_delegate_unittest.cc (revision 72158) |
+++ chrome/browser/download/download_request_infobar_delegate_unittest.cc (working copy) |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -6,36 +6,27 @@ |
#include "chrome/browser/download/download_request_limiter.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+// MockTabDownloadState ------------------------------------------------------- |
+ |
class MockTabDownloadState : public DownloadRequestLimiter::TabDownloadState { |
public: |
- MockTabDownloadState() : responded_(false), accepted_(false) { |
- } |
+ MockTabDownloadState(); |
+ virtual ~MockTabDownloadState(); |
- virtual ~MockTabDownloadState() { |
- EXPECT_TRUE(responded_); |
- } |
+ // DownloadRequestLimiter::TabDownloadState |
+ virtual void Cancel(); |
+ virtual void Accept(); |
- virtual void Accept() { |
- EXPECT_FALSE(responded_); |
- responded_ = true; |
- accepted_ = true; |
+ ConfirmInfoBarDelegate* infobar() { |
+ return infobar_->AsConfirmInfoBarDelegate(); |
} |
+ bool responded() const { return responded_; } |
+ bool accepted() const { return accepted_; } |
- virtual void Cancel() { |
- EXPECT_FALSE(responded_); |
- responded_ = true; |
- accepted_ = false; |
- } |
+ private: |
+ // The actual infobar delegate we're listening to. |
+ scoped_ptr<InfoBarDelegate> infobar_; |
- bool responded() { |
- return responded_; |
- } |
- |
- bool accepted() { |
- return responded_ && accepted_; |
- } |
- |
- private: |
// True if we have gotten some sort of response. |
bool responded_; |
@@ -44,23 +35,44 @@ |
bool accepted_; |
}; |
-TEST(DownloadRequestInfobar, AcceptTest) { |
+MockTabDownloadState::MockTabDownloadState() |
+ : responded_(false), accepted_(false) { |
+ infobar_.reset(new DownloadRequestInfoBarDelegate(NULL, this)); |
+} |
+ |
+MockTabDownloadState::~MockTabDownloadState() { |
+ EXPECT_TRUE(responded_); |
+} |
+ |
+void MockTabDownloadState::Cancel() { |
+ EXPECT_FALSE(responded_); |
+ responded_ = true; |
+ accepted_ = false; |
+} |
+ |
+void MockTabDownloadState::Accept() { |
+ EXPECT_FALSE(responded_); |
+ responded_ = true; |
+ accepted_ = true; |
+} |
+ |
+ |
+// Tests ---------------------------------------------------------------------- |
+ |
+TEST(DownloadRequestInfobarDelegate, AcceptTest) { |
MockTabDownloadState state; |
- DownloadRequestInfoBarDelegate infobar(NULL, &state); |
- infobar.Accept(); |
+ state.infobar()->Accept(); |
EXPECT_TRUE(state.accepted()); |
} |
-TEST(DownloadRequestInfobar, CancelTest) { |
+TEST(DownloadRequestInfobarDelegate, CancelTest) { |
MockTabDownloadState state; |
- DownloadRequestInfoBarDelegate infobar(NULL, &state); |
- infobar.Cancel(); |
+ state.infobar()->Cancel(); |
EXPECT_FALSE(state.accepted()); |
} |
-TEST(DownloadRequestInfobar, CloseTest) { |
+TEST(DownloadRequestInfobarDelegate, CloseTest) { |
MockTabDownloadState state; |
- DownloadRequestInfoBarDelegate infobar(NULL, &state); |
- infobar.InfoBarClosed(); |
+ state.infobar()->InfoBarClosed(); |
EXPECT_FALSE(state.accepted()); |
} |