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