OLD | NEW |
---|---|
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 WebsiteSettingsBubbleControllerForTesting |
estark
2017/03/20 20:19:17
PageInfoBubbleControllerForTesting?
lgarron
2017/03/20 23:09:03
Seems my search didn't include Objective-C++ files
| |
38 : WebsiteSettingsBubbleController { | 38 : PageInfoBubbleController { |
39 @private | 39 @private |
40 CGFloat defaultWindowWidth_; | 40 CGFloat defaultWindowWidth_; |
41 } | 41 } |
42 @end | 42 @end |
43 | 43 |
44 @implementation WebsiteSettingsBubbleControllerForTesting | 44 @implementation WebsiteSettingsBubbleControllerForTesting |
45 - (void)setDefaultWindowWidth:(CGFloat)width { | 45 - (void)setDefaultWindowWidth:(CGFloat)width { |
46 defaultWindowWidth_ = width; | 46 defaultWindowWidth_ = width; |
47 } | 47 } |
48 - (CGFloat)defaultWindowWidth { | 48 - (CGFloat)defaultWindowWidth { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 class WebsiteSettingsBubbleControllerTest : public CocoaTest { | 86 class WebsiteSettingsBubbleControllerTest : public CocoaTest { |
87 public: | 87 public: |
88 WebsiteSettingsBubbleControllerTest() { controller_ = nil; } | 88 WebsiteSettingsBubbleControllerTest() { controller_ = nil; } |
89 | 89 |
90 void TearDown() override { | 90 void TearDown() override { |
91 [controller_ close]; | 91 [controller_ close]; |
92 CocoaTest::TearDown(); | 92 CocoaTest::TearDown(); |
93 } | 93 } |
94 | 94 |
95 protected: | 95 protected: |
96 WebsiteSettingsUIBridge* bridge_; // Weak, owned by controller. | 96 PageInfoUIBridge* bridge_; // Weak, owned by controller. |
97 | 97 |
98 enum MatchType { TEXT_EQUAL = 0, TEXT_NOT_EQUAL }; | 98 enum MatchType { TEXT_EQUAL = 0, TEXT_NOT_EQUAL }; |
99 | 99 |
100 // Creates a new website settings bubble, with the given default width. | 100 // Creates a new website settings bubble, with the given default width. |
101 // If |default_width| is 0, the *default* default width will be used. | 101 // If |default_width| is 0, the *default* default width will be used. |
102 void CreateBubbleWithWidth(CGFloat default_width) { | 102 void CreateBubbleWithWidth(CGFloat default_width) { |
103 bridge_ = new WebsiteSettingsUIBridge(nullptr); | 103 bridge_ = new PageInfoUIBridge(nullptr); |
104 | 104 |
105 // The controller cleans up after itself when the window closes. | 105 // The controller cleans up after itself when the window closes. |
106 controller_ = [WebsiteSettingsBubbleControllerForTesting alloc]; | 106 controller_ = [WebsiteSettingsBubbleControllerForTesting alloc]; |
107 [controller_ setDefaultWindowWidth:default_width]; | 107 [controller_ setDefaultWindowWidth:default_width]; |
108 [controller_ initWithParentWindow:test_window() | 108 [controller_ |
109 websiteSettingsUIBridge:bridge_ | 109 initWithParentWindow:test_window() |
110 webContents:web_contents_factory_.CreateWebContents( | 110 PageInfoUIBridge:bridge_ |
111 &profile_) | 111 webContents:web_contents_factory_.CreateWebContents(&profile_) |
112 url:GURL("https://www.google.com")]; | 112 url:GURL("https://www.google.com")]; |
113 window_ = [controller_ window]; | 113 window_ = [controller_ window]; |
114 [controller_ showWindow:nil]; | 114 [controller_ showWindow:nil]; |
115 } | 115 } |
116 | 116 |
117 void CreateBubble() { CreateBubbleWithWidth(0.0); } | 117 void CreateBubble() { CreateBubbleWithWidth(0.0); } |
118 | 118 |
119 // Return a pointer to the first NSTextField found that either matches, or | 119 // Return a pointer to the first NSTextField found that either matches, or |
120 // doesn't match, the given text. | 120 // doesn't match, the given text. |
121 NSTextField* FindTextField(MatchType match_type, NSString* text) { | 121 NSTextField* FindTextField(MatchType match_type, NSString* text) { |
122 // The window's only immediate child is an invisible view that has a flipped | 122 // 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 Loading... | |
155 return views; | 155 return views; |
156 } | 156 } |
157 | 157 |
158 // Sets up the dialog with some test permission settings. | 158 // Sets up the dialog with some test permission settings. |
159 void SetTestPermissions() { | 159 void SetTestPermissions() { |
160 // Create a list of 5 different permissions, corresponding to all the | 160 // Create a list of 5 different permissions, corresponding to all the |
161 // possible settings: | 161 // possible settings: |
162 // - [allow, block, ask] by default | 162 // - [allow, block, ask] by default |
163 // - [block, allow] * [by user, by policy, by extension] | 163 // - [block, allow] * [by user, by policy, by extension] |
164 PermissionInfoList permission_info_list; | 164 PermissionInfoList permission_info_list; |
165 WebsiteSettingsUI::PermissionInfo info; | 165 PageInfoUI::PermissionInfo info; |
166 for (size_t i = 0; i < arraysize(kTestPermissionTypes); ++i) { | 166 for (size_t i = 0; i < arraysize(kTestPermissionTypes); ++i) { |
167 info.type = kTestPermissionTypes[i]; | 167 info.type = kTestPermissionTypes[i]; |
168 info.setting = kTestSettings[i]; | 168 info.setting = kTestSettings[i]; |
169 if (info.setting == CONTENT_SETTING_DEFAULT) | 169 if (info.setting == CONTENT_SETTING_DEFAULT) |
170 info.default_setting = kTestDefaultSettings[i]; | 170 info.default_setting = kTestDefaultSettings[i]; |
171 info.source = kTestSettingSources[i]; | 171 info.source = kTestSettingSources[i]; |
172 info.is_incognito = false; | 172 info.is_incognito = false; |
173 permission_info_list.push_back(info); | 173 permission_info_list.push_back(info); |
174 } | 174 } |
175 ChosenObjectInfoList chosen_object_info_list; | 175 ChosenObjectInfoList chosen_object_info_list; |
176 bridge_->SetPermissionInfo(permission_info_list, | 176 bridge_->SetPermissionInfo(permission_info_list, |
177 std::move(chosen_object_info_list)); | 177 std::move(chosen_object_info_list)); |
178 } | 178 } |
179 | 179 |
180 content::TestBrowserThreadBundle thread_bundle_; | 180 content::TestBrowserThreadBundle thread_bundle_; |
181 TestingProfile profile_; | 181 TestingProfile profile_; |
182 content::TestWebContentsFactory web_contents_factory_; | 182 content::TestWebContentsFactory web_contents_factory_; |
183 | 183 |
184 WebsiteSettingsBubbleControllerForTesting* controller_; // Weak, owns self. | 184 WebsiteSettingsBubbleControllerForTesting* controller_; // Weak, owns self. |
185 NSWindow* window_; // Weak, owned by controller. | 185 NSWindow* window_; // Weak, owned by controller. |
186 }; | 186 }; |
187 | 187 |
188 TEST_F(WebsiteSettingsBubbleControllerTest, ConnectionHelpButton) { | 188 TEST_F(WebsiteSettingsBubbleControllerTest, ConnectionHelpButton) { |
189 WebsiteSettingsUI::IdentityInfo info; | 189 PageInfoUI::IdentityInfo info; |
190 info.site_identity = std::string("example.com"); | 190 info.site_identity = std::string("example.com"); |
191 info.identity_status = WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN; | 191 info.identity_status = PageInfo::SITE_IDENTITY_STATUS_UNKNOWN; |
192 | 192 |
193 CreateBubble(); | 193 CreateBubble(); |
194 | 194 |
195 bridge_->SetIdentityInfo(const_cast<WebsiteSettingsUI::IdentityInfo&>(info)); | 195 bridge_->SetIdentityInfo(const_cast<PageInfoUI::IdentityInfo&>(info)); |
196 | 196 |
197 EXPECT_EQ([[controller_ connectionHelpButton] action], | 197 EXPECT_EQ([[controller_ connectionHelpButton] action], |
198 @selector(openConnectionHelp:)); | 198 @selector(openConnectionHelp:)); |
199 } | 199 } |
200 | 200 |
201 TEST_F(WebsiteSettingsBubbleControllerTest, ResetDecisionsButton) { | 201 TEST_F(WebsiteSettingsBubbleControllerTest, ResetDecisionsButton) { |
202 WebsiteSettingsUI::IdentityInfo info; | 202 PageInfoUI::IdentityInfo info; |
203 info.site_identity = std::string("example.com"); | 203 info.site_identity = std::string("example.com"); |
204 info.identity_status = WebsiteSettings::SITE_IDENTITY_STATUS_UNKNOWN; | 204 info.identity_status = PageInfo::SITE_IDENTITY_STATUS_UNKNOWN; |
205 | 205 |
206 CreateBubble(); | 206 CreateBubble(); |
207 | 207 |
208 // Set identity info, specifying that the button should not be shown. | 208 // Set identity info, specifying that the button should not be shown. |
209 info.show_ssl_decision_revoke_button = false; | 209 info.show_ssl_decision_revoke_button = false; |
210 bridge_->SetIdentityInfo(const_cast<WebsiteSettingsUI::IdentityInfo&>(info)); | 210 bridge_->SetIdentityInfo(const_cast<PageInfoUI::IdentityInfo&>(info)); |
211 EXPECT_EQ([controller_ resetDecisionsButton], nil); | 211 EXPECT_EQ([controller_ resetDecisionsButton], nil); |
212 | 212 |
213 // Set identity info, specifying that the button should be shown. | 213 // Set identity info, specifying that the button should be shown. |
214 info.certificate = net::X509Certificate::CreateFromBytes( | 214 info.certificate = net::X509Certificate::CreateFromBytes( |
215 reinterpret_cast<const char*>(google_der), sizeof(google_der)); | 215 reinterpret_cast<const char*>(google_der), sizeof(google_der)); |
216 info.show_ssl_decision_revoke_button = true; | 216 info.show_ssl_decision_revoke_button = true; |
217 bridge_->SetIdentityInfo(const_cast<WebsiteSettingsUI::IdentityInfo&>(info)); | 217 bridge_->SetIdentityInfo(const_cast<PageInfoUI::IdentityInfo&>(info)); |
218 EXPECT_NE([controller_ resetDecisionsButton], nil); | 218 EXPECT_NE([controller_ resetDecisionsButton], nil); |
219 | 219 |
220 // Check that clicking the button calls the right selector. | 220 // Check that clicking the button calls the right selector. |
221 EXPECT_EQ([[controller_ resetDecisionsButton] action], | 221 EXPECT_EQ([[controller_ resetDecisionsButton] action], |
222 @selector(resetCertificateDecisions:)); | 222 @selector(resetCertificateDecisions:)); |
223 | 223 |
224 // 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 |
225 // 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 |
226 // 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` |
227 // again. | 227 // again. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 } | 294 } |
295 if ([view isKindOfClass:[NSPopUpButton class]]) { | 295 if ([view isKindOfClass:[NSPopUpButton class]]) { |
296 NSPopUpButton* button = static_cast<NSPopUpButton*>(view); | 296 NSPopUpButton* button = static_cast<NSPopUpButton*>(view); |
297 EXPECT_LT(NSMaxX([button frame]), window_width); | 297 EXPECT_LT(NSMaxX([button frame]), window_width); |
298 } | 298 } |
299 } | 299 } |
300 } | 300 } |
301 } | 301 } |
302 | 302 |
303 } // namespace | 303 } // namespace |
OLD | NEW |