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

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: Mac implementation with test 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"
15 18
16 // A simple class to observe when a window is destructing. 19 // A simple class to observe when a window is destructing.
17 @interface WindowObserver : NSObject { 20 @interface WindowObserver : NSObject {
18 BOOL windowIsClosing_; 21 BOOL windowIsClosing_;
19 } 22 }
20 23
21 - (id)initWithWindow:(NSWindow*)window; 24 - (id)initWithWindow:(NSWindow*)window;
22 25
23 - (void)dealloc; 26 - (void)dealloc;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 EXPECT_FALSE(delegate->close_action()); 103 EXPECT_FALSE(delegate->close_action());
101 EXPECT_TRUE(delegate->shown()); 104 EXPECT_TRUE(delegate->shown());
102 return bubble; 105 return bubble;
103 } 106 }
104 107
105 void ToolbarActionsBarBubbleMacTest::TestBubbleButton( 108 void ToolbarActionsBarBubbleMacTest::TestBubbleButton(
106 ToolbarActionsBarBubbleDelegate::CloseAction expected_action) { 109 ToolbarActionsBarBubbleDelegate::CloseAction expected_action) {
107 TestToolbarActionsBarBubbleDelegate delegate( 110 TestToolbarActionsBarBubbleDelegate delegate(
108 HeadingString(), BodyString(), ActionString()); 111 HeadingString(), BodyString(), ActionString());
109 delegate.set_dismiss_button_text(DismissString()); 112 delegate.set_dismiss_button_text(DismissString());
110 delegate.set_learn_more_button_text(LearnMoreString()); 113
114 ToolbarActionsBarBubbleDelegate::ExtraViewInfo extra_view_info_linked_text;
115 extra_view_info_linked_text.text = LearnMoreString();
116 extra_view_info_linked_text.is_text_linked = true;
117 delegate.set_extra_view_info(extra_view_info_linked_text);
118
111 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate); 119 ToolbarActionsBarBubbleMac* bubble = CreateAndShowBubble(&delegate);
112 base::scoped_nsobject<WindowObserver> windowObserver( 120 base::scoped_nsobject<WindowObserver> windowObserver(
113 [[WindowObserver alloc] initWithWindow:[bubble window]]); 121 [[WindowObserver alloc] initWithWindow:[bubble window]]);
114 EXPECT_FALSE([windowObserver windowIsClosing]); 122 EXPECT_FALSE([windowObserver windowIsClosing]);
115 123
116 // Find the appropriate button to click. 124 // Find the appropriate button to click.
117 NSButton* button = nil; 125 NSButton* button = nil;
118 switch (expected_action) { 126 switch (expected_action) {
119 case ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE: 127 case ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE:
120 button = [bubble actionButton]; 128 button = [bubble actionButton];
121 break; 129 break;
122 case ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION: 130 case ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION:
123 button = [bubble dismissButton]; 131 button = [bubble dismissButton];
124 break; 132 break;
125 case ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE: 133 case ToolbarActionsBarBubbleDelegate::CLOSE_LINK:
126 button = [bubble learnMoreButton]; 134 button = [bubble link];
127 break; 135 break;
128 case ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION: 136 case ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_DEACTIVATION:
129 NOTREACHED(); // Deactivation is tested below. 137 NOTREACHED(); // Deactivation is tested below.
130 break; 138 break;
131 } 139 }
132 ASSERT_TRUE(button); 140 ASSERT_TRUE(button);
133 141
134 // Click the button. 142 // Click the button.
135 std::pair<NSEvent*, NSEvent*> events = 143 std::pair<NSEvent*, NSEvent*> events =
136 cocoa_test_event_utils::MouseClickInView(button, 1); 144 cocoa_test_event_utils::MouseClickInView(button, 1);
137 [NSApp postEvent:events.second atStart:YES]; 145 [NSApp postEvent:events.second atStart:YES];
138 [NSApp sendEvent:events.first]; 146 [NSApp sendEvent:events.first];
139 chrome::testing::NSRunLoopRunAllPending(); 147 chrome::testing::NSRunLoopRunAllPending();
140 148
141 // The bubble should be closed, and the delegate should be told that the 149 // The bubble should be closed, and the delegate should be told that the
142 // button was clicked. 150 // button was clicked.
143 ASSERT_TRUE(delegate.close_action()); 151 ASSERT_TRUE(delegate.close_action());
144 EXPECT_EQ(expected_action, *delegate.close_action()); 152 EXPECT_EQ(expected_action, *delegate.close_action());
145 EXPECT_TRUE([windowObserver windowIsClosing]); 153 EXPECT_TRUE([windowObserver windowIsClosing]);
146 } 154 }
147 155
148 // Test clicking on the action button and dismissing the bubble. 156 // Test clicking on the action button and dismissing the bubble.
149 TEST_F(ToolbarActionsBarBubbleMacTest, CloseActionAndDismiss) { 157 TEST_F(ToolbarActionsBarBubbleMacTest, CloseActionAndDismiss) {
150 // Test all the possible actions. 158 // Test all the possible actions.
151 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE); 159 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE);
152 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION); 160 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS_USER_ACTION);
153 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE); 161 TestBubbleButton(ToolbarActionsBarBubbleDelegate::CLOSE_LINK);
154 162
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 = IDR_OMNIBOX_HTTPS_POLICY_WARNING;
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