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

Side by Side Diff: chrome/browser/ui/cocoa/page_info/page_info_bubble_controller_unittest.mm

Issue 2754383004: Rename WebsiteSettings code to PageInfo. (Closed)
Patch Set: Upload missing comment fix for WebSettingsUI -> PageInfoUI. Created 3 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/page_info/website_settings_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/page_info/page_info_bubble_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" 12 #include "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
13 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/test/test_browser_thread_bundle.h" 14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "content/public/test/test_web_contents_factory.h" 15 #include "content/public/test/test_web_contents_factory.h"
16 #include "net/test/test_certificate_data.h" 16 #include "net/test/test_certificate_data.h"
17 #include "testing/gtest_mac.h" 17 #include "testing/gtest_mac.h"
18 18
19 @interface WebsiteSettingsBubbleController (ExposedForTesting) 19 @interface PageInfoBubbleController (ExposedForTesting)
20 - (NSView*)permissionsView; 20 - (NSView*)permissionsView;
21 - (NSButton*)resetDecisionsButton; 21 - (NSButton*)resetDecisionsButton;
22 - (NSButton*)connectionHelpButton; 22 - (NSButton*)connectionHelpButton;
23 @end 23 @end
24 24
25 @implementation WebsiteSettingsBubbleController (ExposedForTesting) 25 @implementation PageInfoBubbleController (ExposedForTesting)
26 - (NSView*)permissionsView { 26 - (NSView*)permissionsView {
27 return permissionsView_; 27 return permissionsView_;
28 } 28 }
29 - (NSButton*)resetDecisionsButton { 29 - (NSButton*)resetDecisionsButton {
30 return resetDecisionsButton_; 30 return resetDecisionsButton_;
31 } 31 }
32 - (NSButton*)connectionHelpButton { 32 - (NSButton*)connectionHelpButton {
33 return connectionHelpButton_; 33 return connectionHelpButton_;
34 } 34 }
35 @end 35 @end
36 36
37 @interface WebsiteSettingsBubbleControllerForTesting 37 @interface PageInfoBubbleControllerForTesting : PageInfoBubbleController {
38 : WebsiteSettingsBubbleController {
39 @private 38 @private
40 CGFloat defaultWindowWidth_; 39 CGFloat defaultWindowWidth_;
41 } 40 }
42 @end 41 @end
43 42
44 @implementation WebsiteSettingsBubbleControllerForTesting 43 @implementation PageInfoBubbleControllerForTesting
45 - (void)setDefaultWindowWidth:(CGFloat)width { 44 - (void)setDefaultWindowWidth:(CGFloat)width {
46 defaultWindowWidth_ = width; 45 defaultWindowWidth_ = width;
47 } 46 }
48 - (CGFloat)defaultWindowWidth { 47 - (CGFloat)defaultWindowWidth {
49 // If |defaultWindowWidth_| is 0, use the superclass implementation. 48 // If |defaultWindowWidth_| is 0, use the superclass implementation.
50 return defaultWindowWidth_ ? defaultWindowWidth_ : [super defaultWindowWidth]; 49 return defaultWindowWidth_ ? defaultWindowWidth_ : [super defaultWindowWidth];
51 } 50 }
52 @end 51 @end
53 52
54 namespace { 53 namespace {
(...skipping 21 matching lines...) Expand all
76 75
77 const content_settings::SettingSource kTestSettingSources[] = { 76 const content_settings::SettingSource kTestSettingSources[] = {
78 content_settings::SETTING_SOURCE_USER, 77 content_settings::SETTING_SOURCE_USER,
79 content_settings::SETTING_SOURCE_USER, 78 content_settings::SETTING_SOURCE_USER,
80 content_settings::SETTING_SOURCE_USER, 79 content_settings::SETTING_SOURCE_USER,
81 content_settings::SETTING_SOURCE_USER, 80 content_settings::SETTING_SOURCE_USER,
82 content_settings::SETTING_SOURCE_POLICY, 81 content_settings::SETTING_SOURCE_POLICY,
83 content_settings::SETTING_SOURCE_POLICY, 82 content_settings::SETTING_SOURCE_POLICY,
84 content_settings::SETTING_SOURCE_EXTENSION}; 83 content_settings::SETTING_SOURCE_EXTENSION};
85 84
86 class WebsiteSettingsBubbleControllerTest : public CocoaTest { 85 class PageInfoBubbleControllerTest : public CocoaTest {
87 public: 86 public:
88 WebsiteSettingsBubbleControllerTest() { controller_ = nil; } 87 PageInfoBubbleControllerTest() { controller_ = nil; }
89 88
90 void TearDown() override { 89 void TearDown() override {
91 [controller_ close]; 90 [controller_ close];
92 CocoaTest::TearDown(); 91 CocoaTest::TearDown();
93 } 92 }
94 93
95 protected: 94 protected:
96 WebsiteSettingsUIBridge* bridge_; // Weak, owned by controller. 95 PageInfoUIBridge* bridge_; // Weak, owned by controller.
97 96
98 enum MatchType { TEXT_EQUAL = 0, TEXT_NOT_EQUAL }; 97 enum MatchType { TEXT_EQUAL = 0, TEXT_NOT_EQUAL };
99 98
100 // Creates a new website settings bubble, with the given default width. 99 // Creates a new page info bubble, with the given default width.
101 // If |default_width| is 0, the *default* default width will be used. 100 // If |default_width| is 0, the *default* default width will be used.
102 void CreateBubbleWithWidth(CGFloat default_width) { 101 void CreateBubbleWithWidth(CGFloat default_width) {
103 bridge_ = new WebsiteSettingsUIBridge(nullptr); 102 bridge_ = new PageInfoUIBridge(nullptr);
104 103
105 // The controller cleans up after itself when the window closes. 104 // The controller cleans up after itself when the window closes.
106 controller_ = [WebsiteSettingsBubbleControllerForTesting alloc]; 105 controller_ = [PageInfoBubbleControllerForTesting alloc];
107 [controller_ setDefaultWindowWidth:default_width]; 106 [controller_ setDefaultWindowWidth:default_width];
108 [controller_ initWithParentWindow:test_window() 107 [controller_
109 websiteSettingsUIBridge:bridge_ 108 initWithParentWindow:test_window()
110 webContents:web_contents_factory_.CreateWebContents( 109 pageInfoUIBridge:bridge_
111 &profile_) 110 webContents:web_contents_factory_.CreateWebContents(&profile_)
112 url:GURL("https://www.google.com")]; 111 url:GURL("https://www.google.com")];
113 window_ = [controller_ window]; 112 window_ = [controller_ window];
114 [controller_ showWindow:nil]; 113 [controller_ showWindow:nil];
115 } 114 }
116 115
117 void CreateBubble() { CreateBubbleWithWidth(0.0); } 116 void CreateBubble() { CreateBubbleWithWidth(0.0); }
118 117
119 // Return a pointer to the first NSTextField found that either matches, or 118 // Return a pointer to the first NSTextField found that either matches, or
120 // doesn't match, the given text. 119 // doesn't match, the given text.
121 NSTextField* FindTextField(MatchType match_type, NSString* text) { 120 NSTextField* FindTextField(MatchType match_type, NSString* text) {
122 // The window's only immediate child is an invisible view that has a flipped 121 // The window's only immediate child is an invisible view that has a flipped
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return views; 154 return views;
156 } 155 }
157 156
158 // Sets up the dialog with some test permission settings. 157 // Sets up the dialog with some test permission settings.
159 void SetTestPermissions() { 158 void SetTestPermissions() {
160 // Create a list of 5 different permissions, corresponding to all the 159 // Create a list of 5 different permissions, corresponding to all the
161 // possible settings: 160 // possible settings:
162 // - [allow, block, ask] by default 161 // - [allow, block, ask] by default
163 // - [block, allow] * [by user, by policy, by extension] 162 // - [block, allow] * [by user, by policy, by extension]
164 PermissionInfoList permission_info_list; 163 PermissionInfoList permission_info_list;
165 WebsiteSettingsUI::PermissionInfo info; 164 PageInfoUI::PermissionInfo info;
166 for (size_t i = 0; i < arraysize(kTestPermissionTypes); ++i) { 165 for (size_t i = 0; i < arraysize(kTestPermissionTypes); ++i) {
167 info.type = kTestPermissionTypes[i]; 166 info.type = kTestPermissionTypes[i];
168 info.setting = kTestSettings[i]; 167 info.setting = kTestSettings[i];
169 if (info.setting == CONTENT_SETTING_DEFAULT) 168 if (info.setting == CONTENT_SETTING_DEFAULT)
170 info.default_setting = kTestDefaultSettings[i]; 169 info.default_setting = kTestDefaultSettings[i];
171 info.source = kTestSettingSources[i]; 170 info.source = kTestSettingSources[i];
172 info.is_incognito = false; 171 info.is_incognito = false;
173 permission_info_list.push_back(info); 172 permission_info_list.push_back(info);
174 } 173 }
175 ChosenObjectInfoList chosen_object_info_list; 174 ChosenObjectInfoList chosen_object_info_list;
176 bridge_->SetPermissionInfo(permission_info_list, 175 bridge_->SetPermissionInfo(permission_info_list,
177 std::move(chosen_object_info_list)); 176 std::move(chosen_object_info_list));
178 } 177 }
179 178
180 content::TestBrowserThreadBundle thread_bundle_; 179 content::TestBrowserThreadBundle thread_bundle_;
181 TestingProfile profile_; 180 TestingProfile profile_;
182 content::TestWebContentsFactory web_contents_factory_; 181 content::TestWebContentsFactory web_contents_factory_;
183 182
184 WebsiteSettingsBubbleControllerForTesting* controller_; // Weak, owns self. 183 PageInfoBubbleControllerForTesting* controller_; // Weak, owns self.
185 NSWindow* window_; // Weak, owned by controller. 184 NSWindow* window_; // Weak, owned by controller.
186 }; 185 };
187 186
188 TEST_F(WebsiteSettingsBubbleControllerTest, ConnectionHelpButton) { 187 TEST_F(PageInfoBubbleControllerTest, ConnectionHelpButton) {
189 WebsiteSettingsUI::IdentityInfo info; 188 PageInfoUI::IdentityInfo info;
190 info.site_identity = std::string("example.com"); 189 info.site_identity = std::string("example.com");
191 info.identity_status = WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN; 190 info.identity_status = PageInfo::SITE_IDENTITY_STATUS_UNKNOWN;
192 191
193 CreateBubble(); 192 CreateBubble();
194 193
195 bridge_->SetIdentityInfo(const_cast<WebsiteSettingsUI::IdentityInfo&>(info)); 194 bridge_->SetIdentityInfo(const_cast<PageInfoUI::IdentityInfo&>(info));
196 195
197 EXPECT_EQ([[controller_ connectionHelpButton] action], 196 EXPECT_EQ([[controller_ connectionHelpButton] action],
198 @selector(openConnectionHelp:)); 197 @selector(openConnectionHelp:));
199 } 198 }
200 199
201 TEST_F(WebsiteSettingsBubbleControllerTest, ResetDecisionsButton) { 200 TEST_F(PageInfoBubbleControllerTest, ResetDecisionsButton) {
202 WebsiteSettingsUI::IdentityInfo info; 201 PageInfoUI::IdentityInfo info;
203 info.site_identity = std::string("example.com"); 202 info.site_identity = std::string("example.com");
204 info.identity_status = WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN; 203 info.identity_status = PageInfo::SITE_IDENTITY_STATUS_UNKNOWN;
205 204
206 CreateBubble(); 205 CreateBubble();
207 206
208 // Set identity info, specifying that the button should not be shown. 207 // Set identity info, specifying that the button should not be shown.
209 info.show_ssl_decision_revoke_button = false; 208 info.show_ssl_decision_revoke_button = false;
210 bridge_->SetIdentityInfo(const_cast<WebsiteSettingsUI::IdentityInfo&>(info)); 209 bridge_->SetIdentityInfo(const_cast<PageInfoUI::IdentityInfo&>(info));
211 EXPECT_EQ([controller_ resetDecisionsButton], nil); 210 EXPECT_EQ([controller_ resetDecisionsButton], nil);
212 211
213 // Set identity info, specifying that the button should be shown. 212 // Set identity info, specifying that the button should be shown.
214 info.certificate = net::X509Certificate::CreateFromBytes( 213 info.certificate = net::X509Certificate::CreateFromBytes(
215 reinterpret_cast<const char*>(google_der), sizeof(google_der)); 214 reinterpret_cast<const char*>(google_der), sizeof(google_der));
216 ASSERT_TRUE(info.certificate); 215 ASSERT_TRUE(info.certificate);
217 info.show_ssl_decision_revoke_button = true; 216 info.show_ssl_decision_revoke_button = true;
218 bridge_->SetIdentityInfo(const_cast<WebsiteSettingsUI::IdentityInfo&>(info)); 217 bridge_->SetIdentityInfo(const_cast<PageInfoUI::IdentityInfo&>(info));
219 EXPECT_NE([controller_ resetDecisionsButton], nil); 218 EXPECT_NE([controller_ resetDecisionsButton], nil);
220 219
221 // Check that clicking the button calls the right selector. 220 // Check that clicking the button calls the right selector.
222 EXPECT_EQ([[controller_ resetDecisionsButton] action], 221 EXPECT_EQ([[controller_ resetDecisionsButton] action],
223 @selector(resetCertificateDecisions:)); 222 @selector(resetCertificateDecisions:));
224 223
225 // Since the bubble is only created once per identity, we only need to check 224 // Since the bubble is only created once per identity, we only need to check
226 // the button is *added* when needed. So we don't check that it's removed 225 // the button is *added* when needed. So we don't check that it's removed
227 // when we set an identity with `show_ssl_decision_revoke_button == false` 226 // when we set an identity with `show_ssl_decision_revoke_button == false`
228 // again. 227 // again.
229 } 228 }
230 229
231 TEST_F(WebsiteSettingsBubbleControllerTest, SetPermissionInfo) { 230 TEST_F(PageInfoBubbleControllerTest, SetPermissionInfo) {
232 CreateBubble(); 231 CreateBubble();
233 SetTestPermissions(); 232 SetTestPermissions();
234 233
235 // There should be three subviews per permission. 234 // There should be three subviews per permission.
236 NSArray* subviews = [[controller_ permissionsView] subviews]; 235 NSArray* subviews = [[controller_ permissionsView] subviews];
237 EXPECT_EQ(arraysize(kTestPermissionTypes) * 3, [subviews count]); 236 EXPECT_EQ(arraysize(kTestPermissionTypes) * 3, [subviews count]);
238 237
239 // Ensure that there is a distinct label for each permission. 238 // Ensure that there is a distinct label for each permission.
240 NSMutableSet* labels = [NSMutableSet set]; 239 NSMutableSet* labels = [NSMutableSet set];
241 for (NSView* view in subviews) { 240 for (NSView* view in subviews) {
(...skipping 15 matching lines...) Expand all
257 ++disabled_count; 256 ++disabled_count;
258 } 257 }
259 } 258 }
260 EXPECT_EQ(arraysize(kTestPermissionTypes), [labels count]); 259 EXPECT_EQ(arraysize(kTestPermissionTypes), [labels count]);
261 260
262 // 3 of the buttons should be disabled -- the ones that have a setting source 261 // 3 of the buttons should be disabled -- the ones that have a setting source
263 // of SETTING_SOURCE_POLICY or SETTING_SOURCE_EXTENSION. 262 // of SETTING_SOURCE_POLICY or SETTING_SOURCE_EXTENSION.
264 EXPECT_EQ(3, disabled_count); 263 EXPECT_EQ(3, disabled_count);
265 } 264 }
266 265
267 TEST_F(WebsiteSettingsBubbleControllerTest, WindowWidth) { 266 TEST_F(PageInfoBubbleControllerTest, WindowWidth) {
268 const CGFloat kBigEnoughBubbleWidth = 310; 267 const CGFloat kBigEnoughBubbleWidth = 310;
269 // Creating a window that should fit everything. 268 // Creating a window that should fit everything.
270 CreateBubbleWithWidth(kBigEnoughBubbleWidth); 269 CreateBubbleWithWidth(kBigEnoughBubbleWidth);
271 SetTestPermissions(); 270 SetTestPermissions();
272 271
273 CGFloat window_width = NSWidth([[controller_ window] frame]); 272 CGFloat window_width = NSWidth([[controller_ window] frame]);
274 273
275 // Check the window was made bigger to fit the content. 274 // Check the window was made bigger to fit the content.
276 EXPECT_EQ(kBigEnoughBubbleWidth, window_width); 275 EXPECT_EQ(kBigEnoughBubbleWidth, window_width);
277 276
(...skipping 17 matching lines...) Expand all
295 } 294 }
296 if ([view isKindOfClass:[NSPopUpButton class]]) { 295 if ([view isKindOfClass:[NSPopUpButton class]]) {
297 NSPopUpButton* button = static_cast<NSPopUpButton*>(view); 296 NSPopUpButton* button = static_cast<NSPopUpButton*>(view);
298 EXPECT_LT(NSMaxX([button frame]), window_width); 297 EXPECT_LT(NSMaxX([button frame]), window_width);
299 } 298 }
300 } 299 }
301 } 300 }
302 } 301 }
303 302
304 } // namespace 303 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698