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

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: Rebase master Created 4 years, 2 months 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);
(...skipping 16 matching lines...) Expand all
153 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); 162 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE);
154 163
155 { 164 {
156 // Test dismissing the bubble without clicking the button. 165 // Test dismissing the bubble without clicking the button.
157 TestToolbarActionsBarBubbleDelegate delegate( 166 TestToolbarActionsBarBubbleDelegate delegate(
158 HeadingString(), BodyString(), ActionString()); 167 HeadingString(), BodyString(), ActionString());
159 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 168 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
160 base::scoped_nsobject<WindowObserver> windowObserver( 169 base::scoped_nsobject<WindowObserver> windowObserver(
161 [[WindowObserver alloc] initWithWindow:[bubble window]]); 170 [[WindowObserver alloc] initWithWindow:[bubble window]]);
162 EXPECT_FALSE([windowObserver windowIsClosing]); 171 EXPECT_FALSE([windowObserver windowIsClosing]);
163
Devlin 2016/10/20 17:04:07 nit: try not to make extraneous whitespace changes
catmullings 2016/10/21 03:49:29 Done.
164 // Close the bubble. The delegate should be told it was dismissed. 172 // Close the bubble. The delegate should be told it was dismissed.
165 [bubble close]; 173 [bubble close];
166 chrome::testing::NSRunLoopRunAllPending(); 174 chrome::testing::NSRunLoopRunAllPending();
167 ASSERT_TRUE(delegate.close_action()); 175 ASSERT_TRUE(delegate.close_action());
168 EXPECT_EQ(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION, 176 EXPECT_EQ(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION,
169 *delegate.close_action()); 177 *delegate.close_action());
170 EXPECT_TRUE([windowObserver windowIsClosing]); 178 EXPECT_TRUE([windowObserver windowIsClosing]);
171 } 179 }
172 } 180 }
173 181
174 // Test the basic layout of the bubble. 182 // Test the basic layout of the bubble.
175 TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) { 183 TEST_F(ToolbarActionsBarBubbleMacTest, ToolbarActionsBarBubbleLayout) {
176 // Test with no optional fields. 184 // Test with no optional fields.
177 { 185 {
178 TestToolbarActionsBarBubbleDelegate delegate( 186 TestToolbarActionsBarBubbleDelegate delegate(
179 HeadingString(), BodyString(), ActionString()); 187 HeadingString(), BodyString(), ActionString());
180 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 188 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
181 EXPECT_TRUE([bubble actionButton]); 189 EXPECT_TRUE([bubble actionButton]);
182 EXPECT_FALSE([bubble learnMoreButton]); 190 EXPECT_FALSE([bubble iconView]);
191 EXPECT_FALSE([bubble label]);
192 EXPECT_FALSE([bubble link]);
183 EXPECT_FALSE([bubble dismissButton]); 193 EXPECT_FALSE([bubble dismissButton]);
184 EXPECT_FALSE([bubble itemList]); 194 EXPECT_FALSE([bubble itemList]);
185 195
186 [bubble close]; 196 [bubble close];
187 chrome::testing::NSRunLoopRunAllPending(); 197 chrome::testing::NSRunLoopRunAllPending();
188 } 198 }
189 199
190 // Test with all possible buttons (action, learn more, dismiss). 200 // Test with all possible buttons (action, link, dismiss).
191 { 201 {
192 TestToolbarActionsBarBubbleDelegate delegate( 202 TestToolbarActionsBarBubbleDelegate delegate(
193 HeadingString(), BodyString(), ActionString()); 203 HeadingString(), BodyString(), ActionString());
204
205 ToolbarActionsBarBubbleDelegate::ExtraViewInfo extra_view_info_linked_text;
206 extra_view_info_linked_text.text = LearnMoreString();
207 extra_view_info_linked_text.is_text_linked = true;
208 delegate.set_extra_view_info(extra_view_info_linked_text);
209
194 delegate.set_dismiss_button_text(DismissString()); 210 delegate.set_dismiss_button_text(DismissString());
195 delegate.set_learn_more_button_text(LearnMoreString());
196 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 211 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
197 EXPECT_TRUE([bubble actionButton]); 212 EXPECT_TRUE([bubble actionButton]);
198 EXPECT_TRUE([bubble learnMoreButton]); 213 EXPECT_FALSE([bubble iconView]);
214 EXPECT_FALSE([bubble label]);
215 EXPECT_TRUE([bubble link]);
199 EXPECT_TRUE([bubble dismissButton]); 216 EXPECT_TRUE([bubble dismissButton]);
200 EXPECT_FALSE([bubble itemList]); 217 EXPECT_FALSE([bubble itemList]);
201 218
202 [bubble close]; 219 [bubble close];
203 chrome::testing::NSRunLoopRunAllPending(); 220 chrome::testing::NSRunLoopRunAllPending();
204 } 221 }
205 222
206 // Test with only a dismiss button (no action button). 223 // Test with only a dismiss button (no action button).
207 { 224 {
208 TestToolbarActionsBarBubbleDelegate delegate( 225 TestToolbarActionsBarBubbleDelegate delegate(
209 HeadingString(), BodyString(), base::string16()); 226 HeadingString(), BodyString(), base::string16());
210 delegate.set_dismiss_button_text(DismissString()); 227 delegate.set_dismiss_button_text(DismissString());
211 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 228 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
212 EXPECT_FALSE([bubble actionButton]); 229 EXPECT_FALSE([bubble actionButton]);
213 EXPECT_FALSE([bubble learnMoreButton]); 230 EXPECT_FALSE([bubble iconView]);
231 EXPECT_FALSE([bubble label]);
232 EXPECT_FALSE([bubble link]);
214 EXPECT_TRUE([bubble dismissButton]); 233 EXPECT_TRUE([bubble dismissButton]);
215 EXPECT_FALSE([bubble itemList]); 234 EXPECT_FALSE([bubble itemList]);
216 235
217 [bubble close]; 236 [bubble close];
218 chrome::testing::NSRunLoopRunAllPending(); 237 chrome::testing::NSRunLoopRunAllPending();
219 } 238 }
220 239
221 // Test with an action button and an item list. 240 // Test with an action button and an item list.
222 { 241 {
223 TestToolbarActionsBarBubbleDelegate delegate( 242 TestToolbarActionsBarBubbleDelegate delegate(
224 HeadingString(), BodyString(), ActionString()); 243 HeadingString(), BodyString(), ActionString());
225 delegate.set_item_list_text(ItemListString()); 244 delegate.set_item_list_text(ItemListString());
226 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 245 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
227 EXPECT_TRUE([bubble actionButton]); 246 EXPECT_TRUE([bubble actionButton]);
228 EXPECT_FALSE([bubble learnMoreButton]); 247 EXPECT_FALSE([bubble iconView]);
248 EXPECT_FALSE([bubble label]);
249 EXPECT_FALSE([bubble link]);
229 EXPECT_FALSE([bubble dismissButton]); 250 EXPECT_FALSE([bubble dismissButton]);
230 EXPECT_TRUE([bubble itemList]); 251 EXPECT_TRUE([bubble itemList]);
231 252
232 [bubble close]; 253 [bubble close];
233 chrome::testing::NSRunLoopRunAllPending(); 254 chrome::testing::NSRunLoopRunAllPending();
234 } 255 }
235 256
257 // Test with an extra view of a (unlinked) text and icon and action button.
258 {
259 TestToolbarActionsBarBubbleDelegate delegate(HeadingString(), BodyString(),
260 ActionString());
261
262 ToolbarActionsBarBubbleDelegate::ExtraViewInfo extra_view_info;
263 extra_view_info.resource_id = gfx::VectorIconId::BUSINESS;
264 extra_view_info.text =
265 l10n_util::GetStringUTF16(IDS_EXTENSIONS_INSTALLED_BY_ADMIN);
266 extra_view_info.is_text_linked = false;
267 delegate.set_extra_view_info(extra_view_info);
268
269 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
270 EXPECT_TRUE([bubble actionButton]);
271 EXPECT_TRUE([bubble iconView]);
272 EXPECT_TRUE([bubble label]);
273 EXPECT_FALSE([bubble link]);
274 EXPECT_FALSE([bubble dismissButton]);
275 EXPECT_FALSE([bubble itemList]);
276
277 [bubble close];
278 chrome::testing::NSRunLoopRunAllPending();
279 }
280
236 // Test with all possible fields. 281 // Test with all possible fields.
237 { 282 {
238 TestToolbarActionsBarBubbleDelegate delegate( 283 TestToolbarActionsBarBubbleDelegate delegate(
239 HeadingString(), BodyString(), ActionString()); 284 HeadingString(), BodyString(), ActionString());
285
286 ToolbarActionsBarBubbleDelegate::ExtraViewInfo extra_view_info_linked_text;
287 extra_view_info_linked_text.text = LearnMoreString();
288 extra_view_info_linked_text.is_text_linked = true;
289 delegate.set_extra_view_info(extra_view_info_linked_text);
290
240 delegate.set_dismiss_button_text(DismissString()); 291 delegate.set_dismiss_button_text(DismissString());
241 delegate.set_learn_more_button_text(LearnMoreString());
242 delegate.set_item_list_text(ItemListString()); 292 delegate.set_item_list_text(ItemListString());
243 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 293 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
244 EXPECT_TRUE([bubble actionButton]); 294 EXPECT_TRUE([bubble actionButton]);
245 EXPECT_TRUE([bubble learnMoreButton]); 295 EXPECT_FALSE([bubble iconView]);
296 EXPECT_FALSE([bubble label]);
297 EXPECT_TRUE([bubble link]);
246 EXPECT_TRUE([bubble dismissButton]); 298 EXPECT_TRUE([bubble dismissButton]);
247 EXPECT_TRUE([bubble itemList]); 299 EXPECT_TRUE([bubble itemList]);
248 300
249 [bubble close]; 301 [bubble close];
250 chrome::testing::NSRunLoopRunAllPending(); 302 chrome::testing::NSRunLoopRunAllPending();
251 } 303 }
252 } 304 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698