Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac_unittest.mm

Issue 2206693002: Improve settings override bubble to indicate policy installed extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/logging.h" 5 #include "base/logging.h"
6 #import "base/mac/foundation_util.h" 6 #import "base/mac/foundation_util.h"
7 #import "base/mac/scoped_nsobject.h" 7 #import "base/mac/scoped_nsobject.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 10 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
11 #import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.h" 11 #import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.h"
12 #include "chrome/browser/ui/cocoa/run_loop_testing.h" 12 #include "chrome/browser/ui/cocoa/run_loop_testing.h"
13 #include "chrome/browser/ui/toolbar/test_toolbar_actions_bar_bubble_delegate.h" 13 #include "chrome/browser/ui/toolbar/test_toolbar_actions_bar_bubble_delegate.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "components/grit/components_scaled_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
14 #import "ui/events/test/cocoa_test_event_utils.h" 17 #import "ui/events/test/cocoa_test_event_utils.h"
18 #include "ui/gfx/vector_icons_public.h"
15 19
16 // A simple class to observe when a window is destructing. 20 // A simple class to observe when a window is destructing.
17 @interface WindowObserver : NSObject { 21 @interface WindowObserver : NSObject {
18 BOOL windowIsClosing_; 22 BOOL windowIsClosing_;
19 } 23 }
20 24
21 - (id)initWithWindow:(NSWindow*)window; 25 - (id)initWithWindow:(NSWindow*)window;
22 26
23 - (void)dealloc; 27 - (void)dealloc;
24 28
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 EXPECT_FALSE(delegate->close_action()); 104 EXPECT_FALSE(delegate->close_action());
101 EXPECT_TRUE(delegate->shown()); 105 EXPECT_TRUE(delegate->shown());
102 return bubble; 106 return bubble;
103 } 107 }
104 108
105 void ToolbarActionsBarBubbleMacTest::TestBubbleButton( 109 void ToolbarActionsBarBubbleMacTest::TestBubbleButton(
106 ToolbarActionsBarBubbleDelegate::CloseAction expected_action) { 110 ToolbarActionsBarBubbleDelegate::CloseAction expected_action) {
107 TestToolbarActionsBarBubbleDelegate delegate( 111 TestToolbarActionsBarBubbleDelegate delegate(
108 HeadingString(), BodyString(), ActionString()); 112 HeadingString(), BodyString(), ActionString());
109 delegate.set_dismiss_button_text(DismissString()); 113 delegate.set_dismiss_button_text(DismissString());
110 delegate.set_learn_more_button_text(LearnMoreString()); 114
115 ToolbarActionsBarBubbleDelegate::ExtraViewInfo extra_view_info_linked_text;
116 extra_view_info_linked_text.text = LearnMoreString();
117 extra_view_info_linked_text.is_text_linked = true;
118 delegate.set_extra_view_info(extra_view_info_linked_text);
119
111 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 120 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
112 base::scoped_nsobject<WindowObserver> windowObserver( 121 base::scoped_nsobject<WindowObserver> windowObserver(
113 [[WindowObserver alloc] initWithWindow:[bubble window]]); 122 [[WindowObserver alloc] initWithWindow:[bubble window]]);
114 EXPECT_FALSE([windowObserver windowIsClosing]); 123 EXPECT_FALSE([windowObserver windowIsClosing]);
115 124
116 // Find the appropriate button to click. 125 // Find the appropriate button to click.
117 NSButton* button = nil; 126 NSButton* button = nil;
118 switch (expected_action) { 127 switch (expected_action) {
119 case ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE: 128 case ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE:
120 button = [bubble actionButton]; 129 button = [bubble actionButton];
121 break; 130 break;
122 case ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION: 131 case ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION:
123 button = [bubble dismissButton]; 132 button = [bubble dismissButton];
124 break; 133 break;
125 case ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE: 134 case ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE:
126 button = [bubble learnMoreButton]; 135 button = [bubble link];
127 break; 136 break;
128 case ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION: 137 case ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION:
129 NOTREACHED(); // Deactivation is tested below. 138 NOTREACHED(); // Deactivation is tested below.
130 break; 139 break;
131 } 140 }
132 ASSERT_TRUE(button); 141 ASSERT_TRUE(button);
133 142
134 // Click the button. 143 // Click the button.
135 std::pair<NSEvent*, NSEvent*> events = 144 std::pair<NSEvent*, NSEvent*> events =
136 cocoa_test_event_utils::MouseClickInView(button, 1); 145 cocoa_test_event_utils::MouseClickInView(button, 1);
137 [NSApp postEvent:events.second atStart:YES]; 146 [NSApp postEvent:events.second atStart:YES];
138 [NSApp sendEvent:events.first]; 147 [NSApp sendEvent:events.first];
139 chrome::testing::NSRunLoopRunAllPending(); 148 chrome::testing::NSRunLoopRunAllPending();
140 149
141 // The bubble should be closed, and the delegate should be told that the 150 // The bubble should be closed, and the delegate should be told that the
142 // button was clicked. 151 // button was clicked.
143 ASSERT_TRUE(delegate.close_action()); 152 ASSERT_TRUE(delegate.close_action());
144 EXPECT_EQ(expected_action, *delegate.close_action()); 153 EXPECT_EQ(expected_action, *delegate.close_action());
145 EXPECT_TRUE([windowObserver windowIsClosing]); 154 EXPECT_TRUE([windowObserver windowIsClosing]);
146 } 155 }
147 156
148 // Test clicking on the action button and dismissing the bubble. 157 // Test clicking on the action button and dismissing the bubble.
149 TEST_F(ToolbarActionsBarBubbleMacTest, CloseActionAndDismiss) { 158 TEST_F(ToolbarActionsBarBubbleMacTest, CloseActionAndDismiss) {
150 // Test all the possible actions. 159 // Test all the possible actions.
151 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); 160 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE);
152 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); 161 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION);
153 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); 162 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE);
154
155 { 163 {
156 // Test dismissing the bubble without clicking the button. 164 // Test dismissing the bubble without clicking the button.
157 TestToolbarActionsBarBubbleDelegate delegate( 165 TestToolbarActionsBarBubbleDelegate delegate(
158 HeadingString(), BodyString(), ActionString()); 166 HeadingString(), BodyString(), ActionString());
159 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 167 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
160 base::scoped_nsobject<WindowObserver> windowObserver( 168 base::scoped_nsobject<WindowObserver> windowObserver(
161 [[WindowObserver alloc] initWithWindow:[bubble window]]); 169 [[WindowObserver alloc] initWithWindow:[bubble window]]);
162 EXPECT_FALSE([windowObserver windowIsClosing]); 170 EXPECT_FALSE([windowObserver windowIsClosing]);
163
164 // Close the bubble. The delegate should be told it was dismissed. 171 // Close the bubble. The delegate should be told it was dismissed.
165 [bubble close]; 172 [bubble close];
166 chrome::testing::NSRunLoopRunAllPending(); 173 chrome::testing::NSRunLoopRunAllPending();
167 ASSERT_TRUE(delegate.close_action()); 174 ASSERT_TRUE(delegate.close_action());
168 EXPECT_EQ(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION, 175 EXPECT_EQ(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION,
169 *delegate.close_action()); 176 *delegate.close_action());
170 EXPECT_TRUE([windowObserver windowIsClosing]); 177 EXPECT_TRUE([windowObserver windowIsClosing]);
171 } 178 }
172 } 179 }
173 180
174 // Test the basic layout of the bubble. 181 // Test the basic layout of the bubble.
175 TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) { 182 TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) {
176 // Test with no optional fields. 183 // Test with no optional fields.
177 { 184 {
178 TestToolbarActionsBarBubbleDelegate delegate( 185 TestToolbarActionsBarBubbleDelegate delegate(
179 HeadingString(), BodyString(), ActionString()); 186 HeadingString(), BodyString(), ActionString());
180 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 187 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
181 EXPECT_TRUE([bubble actionButton]); 188 EXPECT_TRUE([bubble actionButton]);
182 EXPECT_FALSE([bubble learnMoreButton]); 189 EXPECT_FALSE([bubble iconView]);
190 EXPECT_FALSE([bubble label]);
191 EXPECT_FALSE([bubble link]);
183 EXPECT_FALSE([bubble dismissButton]); 192 EXPECT_FALSE([bubble dismissButton]);
184 EXPECT_FALSE([bubble itemList]); 193 EXPECT_FALSE([bubble itemList]);
185 194
186 [bubble close]; 195 [bubble close];
187 chrome::testing::NSRunLoopRunAllPending(); 196 chrome::testing::NSRunLoopRunAllPending();
188 } 197 }
189 198
190 // Test with all possible buttons (action, learn more, dismiss). 199 // Test with all possible buttons (action, link, dismiss).
191 { 200 {
192 TestToolbarActionsBarBubbleDelegate delegate( 201 TestToolbarActionsBarBubbleDelegate delegate(
193 HeadingString(), BodyString(), ActionString()); 202 HeadingString(), BodyString(), ActionString());
203
204 ToolbarActionsBarBubbleDelegate::ExtraViewInfo extra_view_info_linked_text;
205 extra_view_info_linked_text.text = LearnMoreString();
206 extra_view_info_linked_text.is_text_linked = true;
207 delegate.set_extra_view_info(extra_view_info_linked_text);
208
194 delegate.set_dismiss_button_text(DismissString()); 209 delegate.set_dismiss_button_text(DismissString());
195 delegate.set_learn_more_button_text(LearnMoreString());
196 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 210 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
197 EXPECT_TRUE([bubble actionButton]); 211 EXPECT_TRUE([bubble actionButton]);
198 EXPECT_TRUE([bubble learnMoreButton]); 212 EXPECT_FALSE([bubble iconView]);
213 EXPECT_FALSE([bubble label]);
214 EXPECT_TRUE([bubble link]);
199 EXPECT_TRUE([bubble dismissButton]); 215 EXPECT_TRUE([bubble dismissButton]);
200 EXPECT_FALSE([bubble itemList]); 216 EXPECT_FALSE([bubble itemList]);
201 217
202 [bubble close]; 218 [bubble close];
203 chrome::testing::NSRunLoopRunAllPending(); 219 chrome::testing::NSRunLoopRunAllPending();
204 } 220 }
205 221
206 // Test with only a dismiss button (no action button). 222 // Test with only a dismiss button (no action button).
207 { 223 {
208 TestToolbarActionsBarBubbleDelegate delegate( 224 TestToolbarActionsBarBubbleDelegate delegate(
209 HeadingString(), BodyString(), base::string16()); 225 HeadingString(), BodyString(), base::string16());
210 delegate.set_dismiss_button_text(DismissString()); 226 delegate.set_dismiss_button_text(DismissString());
211 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 227 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
212 EXPECT_FALSE([bubble actionButton]); 228 EXPECT_FALSE([bubble actionButton]);
213 EXPECT_FALSE([bubble learnMoreButton]); 229 EXPECT_FALSE([bubble iconView]);
230 EXPECT_FALSE([bubble label]);
231 EXPECT_FALSE([bubble link]);
214 EXPECT_TRUE([bubble dismissButton]); 232 EXPECT_TRUE([bubble dismissButton]);
215 EXPECT_FALSE([bubble itemList]); 233 EXPECT_FALSE([bubble itemList]);
216 234
217 [bubble close]; 235 [bubble close];
218 chrome::testing::NSRunLoopRunAllPending(); 236 chrome::testing::NSRunLoopRunAllPending();
219 } 237 }
220 238
221 // Test with an action button and an item list. 239 // Test with an action button and an item list.
222 { 240 {
223 TestToolbarActionsBarBubbleDelegate delegate( 241 TestToolbarActionsBarBubbleDelegate delegate(
224 HeadingString(), BodyString(), ActionString()); 242 HeadingString(), BodyString(), ActionString());
225 delegate.set_item_list_text(ItemListString()); 243 delegate.set_item_list_text(ItemListString());
226 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 244 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
227 EXPECT_TRUE([bubble actionButton]); 245 EXPECT_TRUE([bubble actionButton]);
228 EXPECT_FALSE([bubble learnMoreButton]); 246 EXPECT_FALSE([bubble iconView]);
247 EXPECT_FALSE([bubble label]);
248 EXPECT_FALSE([bubble link]);
229 EXPECT_FALSE([bubble dismissButton]); 249 EXPECT_FALSE([bubble dismissButton]);
230 EXPECT_TRUE([bubble itemList]); 250 EXPECT_TRUE([bubble itemList]);
231 251
232 [bubble close]; 252 [bubble close];
233 chrome::testing::NSRunLoopRunAllPending(); 253 chrome::testing::NSRunLoopRunAllPending();
234 } 254 }
235 255
256 // Test with an extra view of a (unlinked) text and icon and action button.
257 {
258 TestToolbarActionsBarBubbleDelegate delegate(HeadingString(), BodyString(),
259 ActionString());
260
261 ToolbarActionsBarBubbleDelegate::ExtraViewInfo extra_view_info;
262 extra_view_info.resource_id = gfx::VectorIconId::BUSINESS;
263 extra_view_info.text =
264 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSTALLED_BY_ADMIN);
265 extra_view_info.is_text_linked = false;
266 delegate.set_extra_view_info(extra_view_info);
267
268 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
269 EXPECT_TRUE([bubble actionButton]);
270 EXPECT_TRUE([bubble iconView]);
271 EXPECT_TRUE([bubble label]);
272 EXPECT_FALSE([bubble link]);
273 EXPECT_FALSE([bubble dismissButton]);
274 EXPECT_FALSE([bubble itemList]);
275
276 [bubble close];
277 chrome::testing::NSRunLoopRunAllPending();
278 }
279
236 // Test with all possible fields. 280 // Test with all possible fields.
237 { 281 {
238 TestToolbarActionsBarBubbleDelegate delegate( 282 TestToolbarActionsBarBubbleDelegate delegate(
239 HeadingString(), BodyString(), ActionString()); 283 HeadingString(), BodyString(), ActionString());
284
285 ToolbarActionsBarBubbleDelegate::ExtraViewInfo extra_view_info_linked_text;
286 extra_view_info_linked_text.text = LearnMoreString();
287 extra_view_info_linked_text.is_text_linked = true;
288 delegate.set_extra_view_info(extra_view_info_linked_text);
289
240 delegate.set_dismiss_button_text(DismissString()); 290 delegate.set_dismiss_button_text(DismissString());
241 delegate.set_learn_more_button_text(LearnMoreString());
242 delegate.set_item_list_text(ItemListString()); 291 delegate.set_item_list_text(ItemListString());
243 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 292 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
244 EXPECT_TRUE([bubble actionButton]); 293 EXPECT_TRUE([bubble actionButton]);
245 EXPECT_TRUE([bubble learnMoreButton]); 294 EXPECT_FALSE([bubble iconView]);
295 EXPECT_FALSE([bubble label]);
296 EXPECT_TRUE([bubble link]);
246 EXPECT_TRUE([bubble dismissButton]); 297 EXPECT_TRUE([bubble dismissButton]);
247 EXPECT_TRUE([bubble itemList]); 298 EXPECT_TRUE([bubble itemList]);
248 299
249 [bubble close]; 300 [bubble close];
250 chrome::testing::NSRunLoopRunAllPending(); 301 chrome::testing::NSRunLoopRunAllPending();
251 } 302 }
252 } 303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698