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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
// Copyright (c) 2009 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 "chrome/browser/tab_contents/infobar_delegate.h"
namespace {
const wchar_t* kMockAlertInfoBarMessage = L"MockAlertInfoBarMessage";
const wchar_t* kMockLinkInfoBarMessage = L"MockLinkInfoBarMessage";
const wchar_t* kMockLinkInfoBarLink = L"http://dev.chromium.org";
const wchar_t* kMockConfirmInfoBarMessage = L"MockConfirmInfoBarMessage";
}
//////////////////////////////////////////////////////////////////////////
// Mock InfoBarDelgates
class MockAlertInfoBarDelegate : public AlertInfoBarDelegate {
public:
explicit MockAlertInfoBarDelegate()
: AlertInfoBarDelegate(NULL),
message_text_accessed(false),
icon_accessed(false),
closed(false) {
}
virtual std::wstring GetMessageText() const {
message_text_accessed = true;
return kMockAlertInfoBarMessage;
}
virtual SkBitmap* GetIcon() const {
icon_accessed = true;
return NULL;
}
virtual void InfoBarClosed() {
closed = true;
}
// These are declared mutable to get around const-ness issues.
mutable bool message_text_accessed;
mutable bool icon_accessed;
bool closed;
};
class MockLinkInfoBarDelegate : public LinkInfoBarDelegate {
public:
explicit MockLinkInfoBarDelegate()
: LinkInfoBarDelegate(NULL),
message_text_accessed(false),
link_text_accessed(false),
icon_accessed(false),
link_clicked(false),
closed(false),
closes_on_action(true) {
}
virtual std::wstring GetMessageTextWithOffset(size_t* link_offset) const {
message_text_accessed = true;
return kMockLinkInfoBarMessage;
}
virtual std::wstring GetLinkText() const {
link_text_accessed = true;
return kMockLinkInfoBarLink;
}
virtual SkBitmap* GetIcon() const {
icon_accessed = true;
return NULL;
}
virtual bool LinkClicked(WindowOpenDisposition disposition) {
link_clicked = true;
return closes_on_action;
}
virtual void InfoBarClosed() {
closed = true;
}
// These are declared mutable to get around const-ness issues.
mutable bool message_text_accessed;
mutable bool link_text_accessed;
mutable bool icon_accessed;
bool link_clicked;
bool closed;
// Determines whether the infobar closes when an action is taken or not.
bool closes_on_action;
};
class MockConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
explicit MockConfirmInfoBarDelegate()
: ConfirmInfoBarDelegate(NULL),
message_text_accessed(false),
link_text_accessed(false),
icon_accessed(false),
ok_clicked(false),
cancel_clicked(false),
link_clicked(false),
closed(false),
closes_on_action(true) {
}
virtual int GetButtons() const {
return (BUTTON_OK | BUTTON_CANCEL);
}
virtual std::wstring GetButtonLabel(InfoBarButton button) const {
if (button == BUTTON_OK)
return L"OK";
else
return L"Cancel";
}
virtual bool Accept() {
ok_clicked = true;
return closes_on_action;
}
virtual bool Cancel() {
cancel_clicked = true;
return closes_on_action;
}
virtual std::wstring GetMessageText() const {
message_text_accessed = true;
return kMockConfirmInfoBarMessage;
}
virtual SkBitmap* GetIcon() const {
icon_accessed = true;
return NULL;
}
virtual void InfoBarClosed() {
closed = true;
}
virtual std::wstring GetLinkText() {
link_text_accessed = true;
return std::wstring();
}
virtual bool LinkClicked(WindowOpenDisposition disposition) {
link_clicked = true;
return closes_on_action;
}
// These are declared mutable to get around const-ness issues.
mutable bool message_text_accessed;
mutable bool link_text_accessed;
mutable bool icon_accessed;
bool ok_clicked;
bool cancel_clicked;
bool link_clicked;
bool closed;
// Determines whether the infobar closes when an action is taken or not.
bool closes_on_action;
};
|