OLD | NEW |
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/ssl_client_certificate_selector_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.h" |
6 | 6 |
7 #import <SecurityInterface/SFChooseIdentityPanel.h> | 7 #import <SecurityInterface/SFChooseIdentityPanel.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #import "base/mac/mac_util.h" | 10 #import "base/mac/mac_util.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" | 13 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" |
14 #include "chrome/browser/ssl/ssl_client_certificate_selector_test.h" | 14 #include "chrome/browser/ssl/ssl_client_certificate_selector_test.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 18 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
19 #include "content/public/browser/client_certificate_delegate.h" | 19 #include "content/public/browser/client_certificate_delegate.h" |
20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
22 #include "net/cert/x509_certificate.h" | |
23 #include "net/test/cert_test_util.h" | |
24 #include "net/test/test_data_directory.h" | |
25 #import "testing/gtest_mac.h" | 22 #import "testing/gtest_mac.h" |
26 #include "ui/base/cocoa/window_size_constants.h" | 23 #include "ui/base/cocoa/window_size_constants.h" |
27 | 24 |
28 using web_modal::WebContentsModalDialogManager; | 25 using web_modal::WebContentsModalDialogManager; |
29 | 26 |
30 namespace { | 27 namespace { |
31 | 28 |
32 class TestClientCertificateDelegate | 29 class TestClientCertificateDelegate |
33 : public content::ClientCertificateDelegate { | 30 : public content::ClientCertificateDelegate { |
34 public: | 31 public: |
(...skipping 17 matching lines...) Expand all Loading... |
52 } | 49 } |
53 | 50 |
54 private: | 51 private: |
55 bool* destroyed_; | 52 bool* destroyed_; |
56 | 53 |
57 DISALLOW_COPY_AND_ASSIGN(TestClientCertificateDelegate); | 54 DISALLOW_COPY_AND_ASSIGN(TestClientCertificateDelegate); |
58 }; | 55 }; |
59 | 56 |
60 } // namespace | 57 } // namespace |
61 | 58 |
62 class SSLClientCertificateSelectorCocoaTest | 59 typedef SSLClientCertificateSelectorTestBase |
63 : public SSLClientCertificateSelectorTestBase { | 60 SSLClientCertificateSelectorCocoaTest; |
64 public: | |
65 ~SSLClientCertificateSelectorCocoaTest() override; | |
66 | |
67 // InProcessBrowserTest: | |
68 void SetUpInProcessBrowserTestFixture() override; | |
69 | |
70 net::CertificateList GetTestCertificateList(); | |
71 | |
72 private: | |
73 scoped_refptr<net::X509Certificate> mit_davidben_cert_; | |
74 scoped_refptr<net::X509Certificate> foaf_me_chromium_test_cert_; | |
75 net::CertificateList client_cert_list_; | |
76 }; | |
77 | |
78 SSLClientCertificateSelectorCocoaTest:: | |
79 ~SSLClientCertificateSelectorCocoaTest() = default; | |
80 | |
81 void SSLClientCertificateSelectorCocoaTest::SetUpInProcessBrowserTestFixture() { | |
82 SSLClientCertificateSelectorTestBase::SetUpInProcessBrowserTestFixture(); | |
83 | |
84 base::FilePath certs_dir = net::GetTestCertsDirectory(); | |
85 | |
86 mit_davidben_cert_ = net::ImportCertFromFile(certs_dir, "mit.davidben.der"); | |
87 ASSERT_TRUE(mit_davidben_cert_.get()); | |
88 | |
89 foaf_me_chromium_test_cert_ = | |
90 net::ImportCertFromFile(certs_dir, "foaf.me.chromium-test-cert.der"); | |
91 ASSERT_TRUE(foaf_me_chromium_test_cert_.get()); | |
92 | |
93 client_cert_list_.push_back(mit_davidben_cert_); | |
94 client_cert_list_.push_back(foaf_me_chromium_test_cert_); | |
95 } | |
96 | |
97 net::CertificateList | |
98 SSLClientCertificateSelectorCocoaTest::GetTestCertificateList() { | |
99 return client_cert_list_; | |
100 } | |
101 | 61 |
102 // Flaky on 10.7; crbug.com/313243 | 62 // Flaky on 10.7; crbug.com/313243 |
103 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, DISABLED_Basic) { | 63 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, DISABLED_Basic) { |
104 // TODO(kbr): re-enable: http://crbug.com/222296 | 64 // TODO(kbr): re-enable: http://crbug.com/222296 |
105 return; | 65 return; |
106 | 66 |
107 content::WebContents* web_contents = | 67 content::WebContents* web_contents = |
108 browser()->tab_strip_model()->GetActiveWebContents(); | 68 browser()->tab_strip_model()->GetActiveWebContents(); |
109 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 69 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
110 WebContentsModalDialogManager::FromWebContents(web_contents); | 70 WebContentsModalDialogManager::FromWebContents(web_contents); |
111 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); | 71 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); |
112 | 72 |
113 bool destroyed = false; | 73 bool destroyed = false; |
114 SSLClientCertificateSelectorCocoa* selector = [ | 74 SSLClientCertificateSelectorCocoa* selector = [ |
115 [SSLClientCertificateSelectorCocoa alloc] | 75 [SSLClientCertificateSelectorCocoa alloc] |
116 initWithBrowserContext:web_contents->GetBrowserContext() | 76 initWithBrowserContext:web_contents->GetBrowserContext() |
117 certRequestInfo:auth_requestor_->cert_request_info_.get() | 77 certRequestInfo:auth_requestor_->cert_request_info_.get() |
118 delegate:base::WrapUnique(new TestClientCertificateDelegate( | 78 delegate:base::WrapUnique(new TestClientCertificateDelegate( |
119 &destroyed))]; | 79 &destroyed))]; |
120 [selector displayForWebContents:web_contents | 80 [selector displayForWebContents:web_contents]; |
121 clientCerts:GetTestCertificateList()]; | |
122 content::RunAllPendingInMessageLoop(); | 81 content::RunAllPendingInMessageLoop(); |
123 EXPECT_TRUE([selector panel]); | 82 EXPECT_TRUE([selector panel]); |
124 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); | 83 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); |
125 | 84 |
126 WebContentsModalDialogManager::TestApi test_api( | 85 WebContentsModalDialogManager::TestApi test_api( |
127 web_contents_modal_dialog_manager); | 86 web_contents_modal_dialog_manager); |
128 test_api.CloseAllDialogs(); | 87 test_api.CloseAllDialogs(); |
129 content::RunAllPendingInMessageLoop(); | 88 content::RunAllPendingInMessageLoop(); |
130 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); | 89 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); |
131 | 90 |
132 EXPECT_TRUE(destroyed); | 91 EXPECT_TRUE(destroyed); |
133 } | 92 } |
134 | 93 |
135 // Test that switching to another tab correctly hides the sheet. | 94 // Test that switching to another tab correctly hides the sheet. |
136 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, HideShow) { | 95 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, HideShow) { |
137 content::WebContents* web_contents = | 96 content::WebContents* web_contents = |
138 browser()->tab_strip_model()->GetActiveWebContents(); | 97 browser()->tab_strip_model()->GetActiveWebContents(); |
139 SSLClientCertificateSelectorCocoa* selector = [ | 98 SSLClientCertificateSelectorCocoa* selector = [ |
140 [SSLClientCertificateSelectorCocoa alloc] | 99 [SSLClientCertificateSelectorCocoa alloc] |
141 initWithBrowserContext:web_contents->GetBrowserContext() | 100 initWithBrowserContext:web_contents->GetBrowserContext() |
142 certRequestInfo:auth_requestor_->cert_request_info_.get() | 101 certRequestInfo:auth_requestor_->cert_request_info_.get() |
143 delegate:base::WrapUnique( | 102 delegate:base::WrapUnique( |
144 new TestClientCertificateDelegate(nullptr))]; | 103 new TestClientCertificateDelegate(nullptr))]; |
145 [selector displayForWebContents:web_contents | 104 [selector displayForWebContents:web_contents]; |
146 clientCerts:GetTestCertificateList()]; | |
147 content::RunAllPendingInMessageLoop(); | 105 content::RunAllPendingInMessageLoop(); |
148 | 106 |
149 NSWindow* sheetWindow = [[selector overlayWindow] attachedSheet]; | 107 NSWindow* sheetWindow = [[selector overlayWindow] attachedSheet]; |
150 EXPECT_EQ(1.0, [sheetWindow alphaValue]); | 108 EXPECT_EQ(1.0, [sheetWindow alphaValue]); |
151 | 109 |
152 // Switch to another tab and verify that the sheet is hidden. Interaction with | 110 // Switch to another tab and verify that the sheet is hidden. Interaction with |
153 // the tab underneath should not be blocked. | 111 // the tab underneath should not be blocked. |
154 AddBlankTabAndShow(browser()); | 112 AddBlankTabAndShow(browser()); |
155 EXPECT_EQ(0.0, [sheetWindow alphaValue]); | 113 EXPECT_EQ(0.0, [sheetWindow alphaValue]); |
156 EXPECT_TRUE([[selector overlayWindow] ignoresMouseEvents]); | 114 EXPECT_TRUE([[selector overlayWindow] ignoresMouseEvents]); |
(...skipping 26 matching lines...) Expand all Loading... |
183 BOOL selector_was_deallocated = false; | 141 BOOL selector_was_deallocated = false; |
184 | 142 |
185 @autoreleasepool { | 143 @autoreleasepool { |
186 content::WebContents* web_contents = | 144 content::WebContents* web_contents = |
187 browser()->tab_strip_model()->GetActiveWebContents(); | 145 browser()->tab_strip_model()->GetActiveWebContents(); |
188 DeallocTrackingSSLClientCertificateSelectorCocoa* selector = | 146 DeallocTrackingSSLClientCertificateSelectorCocoa* selector = |
189 [[DeallocTrackingSSLClientCertificateSelectorCocoa alloc] | 147 [[DeallocTrackingSSLClientCertificateSelectorCocoa alloc] |
190 initWithBrowserContext:web_contents->GetBrowserContext() | 148 initWithBrowserContext:web_contents->GetBrowserContext() |
191 certRequestInfo:auth_requestor_->cert_request_info_.get() | 149 certRequestInfo:auth_requestor_->cert_request_info_.get() |
192 delegate:nil]; | 150 delegate:nil]; |
193 [selector displayForWebContents:web_contents | 151 [selector displayForWebContents:web_contents]; |
194 clientCerts:GetTestCertificateList()]; | |
195 content::RunAllPendingInMessageLoop(); | 152 content::RunAllPendingInMessageLoop(); |
196 | 153 |
197 selector.wasDeallocated = &selector_was_deallocated; | 154 selector.wasDeallocated = &selector_was_deallocated; |
198 | 155 |
199 [selector.overlayWindow endSheet:selector.overlayWindow.attachedSheet]; | 156 [selector.overlayWindow endSheet:selector.overlayWindow.attachedSheet]; |
200 content::RunAllPendingInMessageLoop(); | 157 content::RunAllPendingInMessageLoop(); |
201 } | 158 } |
202 | 159 |
203 EXPECT_TRUE(selector_was_deallocated); | 160 EXPECT_TRUE(selector_was_deallocated); |
204 | 161 |
205 // Without the workaround, this will crash on Sierra. | 162 // Without the workaround, this will crash on Sierra. |
206 [[NSNotificationCenter defaultCenter] | 163 [[NSNotificationCenter defaultCenter] |
207 postNotificationName:NSPreferredScrollerStyleDidChangeNotification | 164 postNotificationName:NSPreferredScrollerStyleDidChangeNotification |
208 object:nil | 165 object:nil |
209 userInfo:@{ | 166 userInfo:@{ |
210 @"NSScrollerStyle" : @(NSScrollerStyleLegacy) | 167 @"NSScrollerStyle" : @(NSScrollerStyleLegacy) |
211 }]; | 168 }]; |
212 [[NSNotificationCenter defaultCenter] | 169 [[NSNotificationCenter defaultCenter] |
213 postNotificationName:NSPreferredScrollerStyleDidChangeNotification | 170 postNotificationName:NSPreferredScrollerStyleDidChangeNotification |
214 object:nil | 171 object:nil |
215 userInfo:@{ | 172 userInfo:@{ |
216 @"NSScrollerStyle" : @(NSScrollerStyleOverlay) | 173 @"NSScrollerStyle" : @(NSScrollerStyleOverlay) |
217 }]; | 174 }]; |
218 } | 175 } |
OLD | NEW |