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/page_info_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/browser_window.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/browser/ui/cocoa/browser_window_controller.h" |
14 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 15 #import "chrome/browser/ui/cocoa/location_bar/location_icon_decoration.h" |
| 16 #import "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" |
15 #include "content/public/test/test_web_contents_factory.h" | 17 #include "content/public/test/test_web_contents_factory.h" |
16 #include "net/test/test_certificate_data.h" | 18 #include "net/test/test_certificate_data.h" |
17 #include "testing/gtest_mac.h" | 19 #include "testing/gtest_mac.h" |
18 | 20 |
19 @interface PageInfoBubbleController (ExposedForTesting) | 21 @interface PageInfoBubbleController (ExposedForTesting) |
20 - (NSView*)permissionsView; | 22 - (NSView*)permissionsView; |
21 - (NSButton*)resetDecisionsButton; | 23 - (NSButton*)resetDecisionsButton; |
22 - (NSButton*)connectionHelpButton; | 24 - (NSButton*)connectionHelpButton; |
23 @end | 25 @end |
24 | 26 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 const content_settings::SettingSource kTestSettingSources[] = { | 82 const content_settings::SettingSource kTestSettingSources[] = { |
81 content_settings::SETTING_SOURCE_USER, | 83 content_settings::SETTING_SOURCE_USER, |
82 content_settings::SETTING_SOURCE_USER, | 84 content_settings::SETTING_SOURCE_USER, |
83 content_settings::SETTING_SOURCE_USER, | 85 content_settings::SETTING_SOURCE_USER, |
84 content_settings::SETTING_SOURCE_USER, | 86 content_settings::SETTING_SOURCE_USER, |
85 content_settings::SETTING_SOURCE_USER, | 87 content_settings::SETTING_SOURCE_USER, |
86 content_settings::SETTING_SOURCE_POLICY, | 88 content_settings::SETTING_SOURCE_POLICY, |
87 content_settings::SETTING_SOURCE_POLICY, | 89 content_settings::SETTING_SOURCE_POLICY, |
88 content_settings::SETTING_SOURCE_EXTENSION}; | 90 content_settings::SETTING_SOURCE_EXTENSION}; |
89 | 91 |
90 class PageInfoBubbleControllerTest : public CocoaTest { | 92 class PageInfoBubbleControllerTest : public CocoaProfileTest { |
91 public: | 93 public: |
92 PageInfoBubbleControllerTest() { controller_ = nil; } | 94 PageInfoBubbleControllerTest() { controller_ = nil; } |
93 | 95 |
94 void TearDown() override { | 96 void TearDown() override { |
95 [controller_ close]; | 97 [controller_ close]; |
96 CocoaTest::TearDown(); | 98 CocoaProfileTest::TearDown(); |
97 } | 99 } |
98 | 100 |
99 protected: | 101 protected: |
100 PageInfoUIBridge* bridge_; // Weak, owned by controller. | 102 PageInfoUIBridge* bridge_; // Weak, owned by controller. |
101 | 103 |
102 enum MatchType { TEXT_EQUAL = 0, TEXT_NOT_EQUAL }; | 104 enum MatchType { TEXT_EQUAL = 0, TEXT_NOT_EQUAL }; |
103 | 105 |
104 // Creates a new page info bubble, with the given default width. | 106 // Creates a new page info bubble, with the given default width. |
105 // If |default_width| is 0, the *default* default width will be used. | 107 // If |default_width| is 0, the *default* default width will be used. |
106 void CreateBubbleWithWidth(CGFloat default_width) { | 108 void CreateBubbleWithWidth(CGFloat default_width) { |
107 bridge_ = new PageInfoUIBridge(nullptr); | 109 bridge_ = new PageInfoUIBridge(nullptr); |
108 | 110 |
109 // The controller cleans up after itself when the window closes. | 111 // The controller cleans up after itself when the window closes. |
110 controller_ = [PageInfoBubbleControllerForTesting alloc]; | 112 controller_ = [PageInfoBubbleControllerForTesting alloc]; |
111 [controller_ setDefaultWindowWidth:default_width]; | 113 [controller_ setDefaultWindowWidth:default_width]; |
112 [controller_ | 114 [controller_ initWithParentWindow:browser()->window()->GetNativeWindow() |
113 initWithParentWindow:test_window() | 115 pageInfoUIBridge:bridge_ |
114 pageInfoUIBridge:bridge_ | 116 webContents:web_contents_factory_.CreateWebContents( |
115 webContents:web_contents_factory_.CreateWebContents(&profile_) | 117 browser()->profile()) |
116 url:GURL("https://www.google.com")]; | 118 url:GURL("https://www.google.com")]; |
117 window_ = [controller_ window]; | 119 window_ = [controller_ window]; |
118 [controller_ showWindow:nil]; | 120 [controller_ showWindow:nil]; |
119 } | 121 } |
120 | 122 |
121 void CreateBubble() { CreateBubbleWithWidth(0.0); } | 123 void CreateBubble() { CreateBubbleWithWidth(0.0); } |
122 | 124 |
123 // Return a pointer to the first NSTextField found that either matches, or | 125 // Return a pointer to the first NSTextField found that either matches, or |
124 // doesn't match, the given text. | 126 // doesn't match, the given text. |
125 NSTextField* FindTextField(MatchType match_type, NSString* text) { | 127 NSTextField* FindTextField(MatchType match_type, NSString* text) { |
126 // The window's only immediate child is an invisible view that has a flipped | 128 // The window's only immediate child is an invisible view that has a flipped |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 int NumSettingsNotSetByUser() const { | 186 int NumSettingsNotSetByUser() const { |
185 int num_non_user_settings = 0; | 187 int num_non_user_settings = 0; |
186 for (size_t i = 0; i < arraysize(kTestSettingSources); ++i) { | 188 for (size_t i = 0; i < arraysize(kTestSettingSources); ++i) { |
187 num_non_user_settings += | 189 num_non_user_settings += |
188 (kTestSettingSources[i] != content_settings::SETTING_SOURCE_USER) ? 1 | 190 (kTestSettingSources[i] != content_settings::SETTING_SOURCE_USER) ? 1 |
189 : 0; | 191 : 0; |
190 } | 192 } |
191 return num_non_user_settings; | 193 return num_non_user_settings; |
192 } | 194 } |
193 | 195 |
194 content::TestBrowserThreadBundle thread_bundle_; | |
195 TestingProfile profile_; | |
196 content::TestWebContentsFactory web_contents_factory_; | 196 content::TestWebContentsFactory web_contents_factory_; |
197 | 197 |
198 PageInfoBubbleControllerForTesting* controller_; // Weak, owns self. | 198 PageInfoBubbleControllerForTesting* controller_; // Weak, owns self. |
199 NSWindow* window_; // Weak, owned by controller. | 199 NSWindow* window_; // Weak, owned by controller. |
200 }; | 200 }; |
201 | 201 |
202 TEST_F(PageInfoBubbleControllerTest, ConnectionHelpButton) { | 202 TEST_F(PageInfoBubbleControllerTest, ConnectionHelpButton) { |
203 PageInfoUI::IdentityInfo info; | 203 PageInfoUI::IdentityInfo info; |
204 info.site_identity = std::string("example.com"); | 204 info.site_identity = std::string("example.com"); |
205 info.identity_status = PageInfo::SITE_IDENTITY_STATUS_UNKNOWN; | 205 info.identity_status = PageInfo::SITE_IDENTITY_STATUS_UNKNOWN; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 EXPECT_GT(NSMinX([icon frame]), 0); | 311 EXPECT_GT(NSMinX([icon frame]), 0); |
312 } | 312 } |
313 if ([view isKindOfClass:[NSPopUpButton class]]) { | 313 if ([view isKindOfClass:[NSPopUpButton class]]) { |
314 NSPopUpButton* button = static_cast<NSPopUpButton*>(view); | 314 NSPopUpButton* button = static_cast<NSPopUpButton*>(view); |
315 EXPECT_LT(NSMaxX([button frame]), window_width); | 315 EXPECT_LT(NSMaxX([button frame]), window_width); |
316 } | 316 } |
317 } | 317 } |
318 } | 318 } |
319 } | 319 } |
320 | 320 |
| 321 // Tests the page icon decoration's active state. |
| 322 TEST_F(PageInfoBubbleControllerTest, PageIconDecorationActiveState) { |
| 323 NSWindow* window = browser()->window()->GetNativeWindow(); |
| 324 BrowserWindowController* controller = |
| 325 [BrowserWindowController browserWindowControllerForWindow:window]; |
| 326 LocationBarDecoration* decoration = |
| 327 [controller locationBarBridge]->GetPageInfoDecoration(); |
| 328 |
| 329 CreateBubble(); |
| 330 EXPECT_TRUE([[controller_ window] isVisible]); |
| 331 EXPECT_TRUE(decoration->active()); |
| 332 |
| 333 [controller_ close]; |
| 334 EXPECT_FALSE(decoration->active()); |
| 335 } |
| 336 |
321 } // namespace | 337 } // namespace |
OLD | NEW |