| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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 "app/l10n_util.h" | |
| 6 #include "base/scoped_ptr.h" | |
| 7 #include "chrome/browser/autofill/autofill_infobar_delegate.h" | |
| 8 #include "chrome/browser/autofill/autofill_manager.h" | |
| 9 #include "chrome/browser/tab_contents/infobar_delegate.h" | |
| 10 #include "chrome/browser/tab_contents/navigation_controller.h" | |
| 11 #include "grit/chromium_strings.h" | |
| 12 #include "grit/generated_resources.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 class SkBitmap; | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 class MockAutoFillManager : public AutoFillManager { | |
| 20 public: | |
| 21 explicit MockAutoFillManager() | |
| 22 : responded_(false), | |
| 23 accepted_(false) {} | |
| 24 | |
| 25 virtual void OnInfoBarClosed() { | |
| 26 EXPECT_FALSE(responded_); | |
| 27 responded_ = true; | |
| 28 accepted_ = true; | |
| 29 } | |
| 30 | |
| 31 virtual void OnInfoBarAccepted() { | |
| 32 EXPECT_FALSE(responded_); | |
| 33 responded_ = true; | |
| 34 accepted_ = true; | |
| 35 } | |
| 36 | |
| 37 virtual void OnInfoBarCancelled() { | |
| 38 EXPECT_FALSE(responded_); | |
| 39 responded_ = true; | |
| 40 accepted_ = false; | |
| 41 } | |
| 42 | |
| 43 bool responded() { | |
| 44 return responded_; | |
| 45 } | |
| 46 | |
| 47 bool accepted() { | |
| 48 return accepted_; | |
| 49 } | |
| 50 | |
| 51 private: | |
| 52 // True if we have gotten some sort of response. | |
| 53 bool responded_; | |
| 54 | |
| 55 // True if we have gotten an Accept response. Meaningless if |responded_| is | |
| 56 // not true. | |
| 57 bool accepted_; | |
| 58 | |
| 59 DISALLOW_COPY_AND_ASSIGN(MockAutoFillManager); | |
| 60 }; | |
| 61 | |
| 62 class AutoFillInfoBarDelegateTest : public testing::Test { | |
| 63 public: | |
| 64 AutoFillInfoBarDelegateTest() {} | |
| 65 | |
| 66 virtual void SetUp() { | |
| 67 autofill_manager_.reset(new MockAutoFillManager()); | |
| 68 infobar_.reset(new AutoFillInfoBarDelegate(NULL, autofill_manager_.get())); | |
| 69 } | |
| 70 | |
| 71 protected: | |
| 72 scoped_ptr<MockAutoFillManager> autofill_manager_; | |
| 73 scoped_ptr<AutoFillInfoBarDelegate> infobar_; | |
| 74 | |
| 75 private: | |
| 76 DISALLOW_COPY_AND_ASSIGN(AutoFillInfoBarDelegateTest); | |
| 77 }; | |
| 78 | |
| 79 TEST_F(AutoFillInfoBarDelegateTest, ShouldExpire) { | |
| 80 NavigationController::LoadCommittedDetails details; | |
| 81 EXPECT_FALSE(infobar_->ShouldExpire(details)); | |
| 82 } | |
| 83 | |
| 84 TEST_F(AutoFillInfoBarDelegateTest, InfoBarClosed) { | |
| 85 infobar_->InfoBarClosed(); | |
| 86 EXPECT_TRUE(autofill_manager_->responded()); | |
| 87 EXPECT_TRUE(autofill_manager_->accepted()); | |
| 88 } | |
| 89 | |
| 90 TEST_F(AutoFillInfoBarDelegateTest, GetMessageText) { | |
| 91 std::wstring text = l10n_util::GetString(IDS_AUTOFILL_INFOBAR_TEXT); | |
| 92 EXPECT_EQ(text, infobar_->GetMessageText()); | |
| 93 } | |
| 94 | |
| 95 TEST_F(AutoFillInfoBarDelegateTest, GetIcon) { | |
| 96 SkBitmap* icon = infobar_->GetIcon(); | |
| 97 EXPECT_NE(static_cast<SkBitmap*>(NULL), icon); | |
| 98 } | |
| 99 | |
| 100 TEST_F(AutoFillInfoBarDelegateTest, GetButtons) { | |
| 101 int buttons = | |
| 102 ConfirmInfoBarDelegate::BUTTON_OK | ConfirmInfoBarDelegate::BUTTON_CANCEL; | |
| 103 EXPECT_EQ(buttons, infobar_->GetButtons()); | |
| 104 } | |
| 105 | |
| 106 TEST_F(AutoFillInfoBarDelegateTest, GetButtonLabel) { | |
| 107 std::wstring accept = l10n_util::GetString(IDS_AUTOFILL_INFOBAR_ACCEPT); | |
| 108 EXPECT_EQ(accept, | |
| 109 infobar_->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); | |
| 110 | |
| 111 std::wstring deny = l10n_util::GetString(IDS_AUTOFILL_INFOBAR_DENY); | |
| 112 EXPECT_EQ(deny, | |
| 113 infobar_->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); | |
| 114 } | |
| 115 | |
| 116 TEST_F(AutoFillInfoBarDelegateTest, Accept) { | |
| 117 infobar_->Accept(); | |
| 118 EXPECT_TRUE(autofill_manager_->responded()); | |
| 119 EXPECT_TRUE(autofill_manager_->accepted()); | |
| 120 } | |
| 121 | |
| 122 TEST_F(AutoFillInfoBarDelegateTest, Cancel) { | |
| 123 infobar_->Cancel(); | |
| 124 EXPECT_TRUE(autofill_manager_->responded()); | |
| 125 EXPECT_FALSE(autofill_manager_->accepted()); | |
| 126 } | |
| 127 | |
| 128 } // namespace | |
| OLD | NEW |