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

Side by Side Diff: chrome/browser/ui/cocoa/website_settings_bubble_controller_unittest.mm

Issue 11443018: Revert 171259 (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1312/src/
Patch Set: Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #import "chrome/browser/ui/cocoa/website_settings_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/website_settings_bubble_controller.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" 8 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
9 #include "testing/gtest_mac.h" 9 #include "testing/gtest_mac.h"
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 - (NSTextField*)firstVisitDescriptionField { 55 - (NSTextField*)firstVisitDescriptionField {
56 return firstVisitDescriptionField_; 56 return firstVisitDescriptionField_;
57 } 57 }
58 58
59 - (NSButton*)helpButton { 59 - (NSButton*)helpButton {
60 return helpButton_; 60 return helpButton_;
61 } 61 }
62 @end 62 @end
63 63
64 @interface WebsiteSettingsBubbleControllerForTesting
65 : WebsiteSettingsBubbleController {
66 @private
67 CGFloat defaultWindowWidth_;
68 }
69 @end
70
71 @implementation WebsiteSettingsBubbleControllerForTesting
72 - (void)setDefaultWindowWidth:(CGFloat)width {
73 defaultWindowWidth_ = width;
74 }
75 - (CGFloat)defaultWindowWidth {
76 // If |defaultWindowWidth_| is 0, use the superclass implementation.
77 return defaultWindowWidth_ ?
78 defaultWindowWidth_ : [super defaultWindowWidth];
79 }
80 @end
81
82 namespace { 64 namespace {
83 65
84 // Indices of the menu items in the permission menu. 66 // Indices of the menu items in the permission menu.
85 enum PermissionMenuIndices { 67 enum PermissionMenuIndices {
86 kMenuIndexContentSettingAllow = 0, 68 kMenuIndexContentSettingAllow = 0,
87 kMenuIndexContentSettingBlock, 69 kMenuIndexContentSettingBlock,
88 kMenuIndexContentSettingDefault 70 kMenuIndexContentSettingDefault
89 }; 71 };
90 72
91 const ContentSettingsType kTestPermissionTypes[] = {
92 // NOTE: FULLSCREEN does not support "Always block", so it must appear as
93 // one of the first three permissions.
94 CONTENT_SETTINGS_TYPE_FULLSCREEN,
95 CONTENT_SETTINGS_TYPE_IMAGES,
96 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
97 CONTENT_SETTINGS_TYPE_PLUGINS,
98 CONTENT_SETTINGS_TYPE_POPUPS,
99 CONTENT_SETTINGS_TYPE_GEOLOCATION,
100 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
101 CONTENT_SETTINGS_TYPE_MOUSELOCK,
102 CONTENT_SETTINGS_TYPE_MEDIASTREAM,
103 };
104
105 const ContentSetting kTestSettings[] = {
106 CONTENT_SETTING_DEFAULT,
107 CONTENT_SETTING_DEFAULT,
108 CONTENT_SETTING_DEFAULT,
109 CONTENT_SETTING_ALLOW,
110 CONTENT_SETTING_BLOCK,
111 CONTENT_SETTING_ALLOW,
112 CONTENT_SETTING_BLOCK,
113 CONTENT_SETTING_ALLOW,
114 CONTENT_SETTING_BLOCK,
115 };
116
117 const ContentSetting kTestDefaultSettings[] = {
118 CONTENT_SETTING_ALLOW,
119 CONTENT_SETTING_BLOCK,
120 CONTENT_SETTING_ASK
121 };
122
123 const content_settings::SettingSource kTestSettingSources[] = {
124 content_settings::SETTING_SOURCE_USER,
125 content_settings::SETTING_SOURCE_USER,
126 content_settings::SETTING_SOURCE_USER,
127 content_settings::SETTING_SOURCE_USER,
128 content_settings::SETTING_SOURCE_USER,
129 content_settings::SETTING_SOURCE_POLICY,
130 content_settings::SETTING_SOURCE_POLICY,
131 content_settings::SETTING_SOURCE_EXTENSION,
132 content_settings::SETTING_SOURCE_EXTENSION,
133 };
134
135 class WebsiteSettingsBubbleControllerTest : public CocoaTest { 73 class WebsiteSettingsBubbleControllerTest : public CocoaTest {
136 public: 74 public:
137 WebsiteSettingsBubbleControllerTest() { 75 WebsiteSettingsBubbleControllerTest() {
138 controller_ = nil; 76 controller_ = nil;
139 } 77 }
140 78
141 virtual void TearDown() { 79 virtual void TearDown() {
142 [controller_ close]; 80 [controller_ close];
143 CocoaTest::TearDown(); 81 CocoaTest::TearDown();
144 } 82 }
145 83
146 protected: 84 protected:
147 WebsiteSettingsUIBridge* bridge_; // Weak, owned by controller. 85 WebsiteSettingsUIBridge* bridge_; // Weak, owned by controller.
148 86
149 enum MatchType { 87 enum MatchType {
150 TEXT_EQUAL = 0, 88 TEXT_EQUAL = 0,
151 TEXT_NOT_EQUAL 89 TEXT_NOT_EQUAL
152 }; 90 };
153 91
154 // Creates a new website settings bubble, with the given default width. 92 void CreateBubble() {
155 // If |default_width| is 0, the *default* default width will be used.
156 void CreateBubbleWithWidth(CGFloat default_width) {
157 bridge_ = new WebsiteSettingsUIBridge(); 93 bridge_ = new WebsiteSettingsUIBridge();
158 94
159 // The controller cleans up after itself when the window closes. 95 // The controller cleans up after itself when the window closes.
160 controller_ = [WebsiteSettingsBubbleControllerForTesting alloc]; 96 controller_ =
161 [controller_ setDefaultWindowWidth:default_width]; 97 [[WebsiteSettingsBubbleController alloc]
162 [controller_ initWithParentWindow:test_window() 98 initWithParentWindow:test_window()
163 websiteSettingsUIBridge:bridge_ 99 websiteSettingsUIBridge:bridge_
164 tabContents:nil 100 tabContents:nil
165 isInternalPage:NO]; 101 isInternalPage:NO];
166 window_ = [controller_ window]; 102 window_ = [controller_ window];
167 [controller_ showWindow:nil]; 103 [controller_ showWindow:nil];
168 } 104 }
169 105
170 void CreateBubble() {
171 CreateBubbleWithWidth(0.0);
172 }
173
174 // Return a pointer to the first NSTextField found that either matches, or 106 // Return a pointer to the first NSTextField found that either matches, or
175 // doesn't match, the given text. 107 // doesn't match, the given text.
176 NSTextField* FindTextField(MatchType match_type, NSString* text) { 108 NSTextField* FindTextField(MatchType match_type, NSString* text) {
177 // The window's only immediate child is an invisible view that has a flipped 109 // The window's only immediate child is an invisible view that has a flipped
178 // coordinate origin. It is into this that all views get placed. 110 // coordinate origin. It is into this that all views get placed.
179 NSArray* window_subviews = [[window_ contentView] subviews]; 111 NSArray* window_subviews = [[window_ contentView] subviews];
180 EXPECT_EQ(1U, [window_subviews count]); 112 EXPECT_EQ(1U, [window_subviews count]);
181 NSArray* subviews = [[window_subviews lastObject] subviews]; 113 NSArray* subviews = [[window_subviews lastObject] subviews];
182 114
183 // Expect 4 views: the identity, identity status, the segmented control 115 // Expect 4 views: the identity, identity status, the segmented control
(...skipping 14 matching lines...) Expand all
198 130
199 NSMutableArray* FindAllSubviewsOfClass(NSView* parent_view, Class a_class) { 131 NSMutableArray* FindAllSubviewsOfClass(NSView* parent_view, Class a_class) {
200 NSMutableArray* views = [NSMutableArray array]; 132 NSMutableArray* views = [NSMutableArray array];
201 for (NSView* view in [parent_view subviews]) { 133 for (NSView* view in [parent_view subviews]) {
202 if ([view isKindOfClass:a_class]) 134 if ([view isKindOfClass:a_class])
203 [views addObject:view]; 135 [views addObject:view];
204 } 136 }
205 return views; 137 return views;
206 } 138 }
207 139
208 // Sets up the dialog with some test permission settings. 140 WebsiteSettingsBubbleController* controller_; // Weak, owns self.
209 void SetTestPermissions() {
210 // Create a list of 5 different permissions, corresponding to all the
211 // possible settings:
212 // - [allow, block, ask] by default
213 // - [block, allow] * [by user, by policy, by extension]
214 PermissionInfoList list;
215 WebsiteSettingsUI::PermissionInfo info;
216 for (size_t i = 0; i < arraysize(kTestPermissionTypes); ++i) {
217 info.type = kTestPermissionTypes[i];
218 info.setting = kTestSettings[i];
219 if (info.setting == CONTENT_SETTING_DEFAULT)
220 info.default_setting = kTestDefaultSettings[i];
221 info.source = kTestSettingSources[i];
222 list.push_back(info);
223 }
224 bridge_->SetPermissionInfo(list);
225 }
226
227 WebsiteSettingsBubbleControllerForTesting* controller_; // Weak, owns self.
228 NSWindow* window_; // Weak, owned by controller. 141 NSWindow* window_; // Weak, owned by controller.
229 }; 142 };
230 143
231 TEST_F(WebsiteSettingsBubbleControllerTest, BasicIdentity) { 144 TEST_F(WebsiteSettingsBubbleControllerTest, BasicIdentity) {
232 WebsiteSettingsUI::IdentityInfo info; 145 WebsiteSettingsUI::IdentityInfo info;
233 info.site_identity = std::string("nhl.com"); 146 info.site_identity = std::string("nhl.com");
234 info.identity_status = WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN; 147 info.identity_status = WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN;
235 148
236 CreateBubble(); 149 CreateBubble();
237 150
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 231
319 TEST_F(WebsiteSettingsBubbleControllerTest, SetFirstVisit) { 232 TEST_F(WebsiteSettingsBubbleControllerTest, SetFirstVisit) {
320 CreateBubble(); 233 CreateBubble();
321 bridge_->SetFirstVisit(ASCIIToUTF16("Yesterday")); 234 bridge_->SetFirstVisit(ASCIIToUTF16("Yesterday"));
322 EXPECT_NSEQ(@"Yesterday", 235 EXPECT_NSEQ(@"Yesterday",
323 [[controller_ firstVisitDescriptionField] stringValue]); 236 [[controller_ firstVisitDescriptionField] stringValue]);
324 } 237 }
325 238
326 TEST_F(WebsiteSettingsBubbleControllerTest, SetPermissionInfo) { 239 TEST_F(WebsiteSettingsBubbleControllerTest, SetPermissionInfo) {
327 CreateBubble(); 240 CreateBubble();
328 SetTestPermissions(); 241
242 const ContentSettingsType kTestPermissionTypes[] = {
243 // NOTE: FULLSCREEN does not support "Always block", so it must appear as
244 // one of the first three permissions.
245 CONTENT_SETTINGS_TYPE_FULLSCREEN,
246 CONTENT_SETTINGS_TYPE_IMAGES,
247 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
248 CONTENT_SETTINGS_TYPE_PLUGINS,
249 CONTENT_SETTINGS_TYPE_POPUPS,
250 CONTENT_SETTINGS_TYPE_GEOLOCATION,
251 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
252 CONTENT_SETTINGS_TYPE_MOUSELOCK,
253 CONTENT_SETTINGS_TYPE_MEDIASTREAM,
254 };
255
256 const ContentSetting kTestSettings[] = {
257 CONTENT_SETTING_DEFAULT,
258 CONTENT_SETTING_DEFAULT,
259 CONTENT_SETTING_DEFAULT,
260 CONTENT_SETTING_ALLOW,
261 CONTENT_SETTING_BLOCK,
262 CONTENT_SETTING_ALLOW,
263 CONTENT_SETTING_BLOCK,
264 CONTENT_SETTING_ALLOW,
265 CONTENT_SETTING_BLOCK,
266 };
267
268 const ContentSetting kTestDefaultSettings[] = {
269 CONTENT_SETTING_ALLOW,
270 CONTENT_SETTING_BLOCK,
271 CONTENT_SETTING_ASK
272 };
273
274 const content_settings::SettingSource kTestSettingSources[] = {
275 content_settings::SETTING_SOURCE_USER,
276 content_settings::SETTING_SOURCE_USER,
277 content_settings::SETTING_SOURCE_USER,
278 content_settings::SETTING_SOURCE_USER,
279 content_settings::SETTING_SOURCE_USER,
280 content_settings::SETTING_SOURCE_POLICY,
281 content_settings::SETTING_SOURCE_POLICY,
282 content_settings::SETTING_SOURCE_EXTENSION,
283 content_settings::SETTING_SOURCE_EXTENSION,
284 };
285
286 // Create a list of 5 different permissions, corresponding to all the
287 // possible settings:
288 // - [allow, block, ask] by default
289 // - [block, allow] * [by user, by policy, by extension]
290 PermissionInfoList list;
291 WebsiteSettingsUI::PermissionInfo info;
292 for (size_t i = 0; i < arraysize(kTestPermissionTypes); ++i) {
293 info.type = kTestPermissionTypes[i];
294 info.setting = kTestSettings[i];
295 if (info.setting == CONTENT_SETTING_DEFAULT)
296 info.default_setting = kTestDefaultSettings[i];
297 info.source = kTestSettingSources[i];
298 list.push_back(info);
299 }
300 bridge_->SetPermissionInfo(list);
329 301
330 // There should be three subviews per permission (an icon, a label and a 302 // There should be three subviews per permission (an icon, a label and a
331 // select box), plus a text label for the Permission section. 303 // select box), plus a text label for the Permission section.
332 NSArray* subviews = [[controller_ permissionsView] subviews]; 304 NSArray* subviews = [[controller_ permissionsView] subviews];
333 EXPECT_EQ(arraysize(kTestPermissionTypes) * 3 + 1, [subviews count]); 305 EXPECT_EQ(arraysize(kTestPermissionTypes) * 3 + 1, [subviews count]);
334 306
335 // Ensure that there is a distinct label for each permission. 307 // Ensure that there is a distinct label for each permission.
336 NSMutableSet* labels = [NSMutableSet set]; 308 NSMutableSet* labels = [NSMutableSet set];
337 for (NSView* view in subviews) { 309 for (NSView* view in subviews) {
338 if ([view isKindOfClass:[NSTextField class]]) 310 if ([view isKindOfClass:[NSTextField class]])
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 // (which implements the tabs) as well as the visible tab contents. 342 // (which implements the tabs) as well as the visible tab contents.
371 // NOTE: This implicitly (and deliberately) tests that the tabs appear in a 343 // NOTE: This implicitly (and deliberately) tests that the tabs appear in a
372 // specific order: Permissions, Connection. 344 // specific order: Permissions, Connection.
373 EXPECT_EQ(0, [segmentedControl selectedSegment]); 345 EXPECT_EQ(0, [segmentedControl selectedSegment]);
374 EXPECT_EQ(0, [tabView indexOfTabViewItem:[tabView selectedTabViewItem]]); 346 EXPECT_EQ(0, [tabView indexOfTabViewItem:[tabView selectedTabViewItem]]);
375 bridge_->SetSelectedTab(WebsiteSettingsUI::TAB_ID_CONNECTION); 347 bridge_->SetSelectedTab(WebsiteSettingsUI::TAB_ID_CONNECTION);
376 EXPECT_EQ(1, [segmentedControl selectedSegment]); 348 EXPECT_EQ(1, [segmentedControl selectedSegment]);
377 EXPECT_EQ(1, [tabView indexOfTabViewItem:[tabView selectedTabViewItem]]); 349 EXPECT_EQ(1, [tabView indexOfTabViewItem:[tabView selectedTabViewItem]]);
378 } 350 }
379 351
380 TEST_F(WebsiteSettingsBubbleControllerTest, WindowWidth) {
381 // Try creating a window that is obviously too small.
382 CreateBubbleWithWidth(30.0);
383 SetTestPermissions();
384
385 CGFloat window_width = NSWidth([[controller_ window] frame]);
386
387 // Check the window was made bigger to fit the content.
388 EXPECT_LT(30.0, window_width);
389
390 // Check that the window is wider than the right edge of all the permission
391 // popup buttons.
392 for (NSView* view in [[controller_ permissionsView] subviews]) {
393 if ([view isKindOfClass:[NSPopUpButton class]]) {
394 NSPopUpButton* button = static_cast<NSPopUpButton*>(view);
395 EXPECT_LT(NSMaxX([button frame]), window_width);
396 }
397 }
398 }
399
400 } // namespace 352 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698