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