| 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 "chrome/browser/ssl/ssl_client_certificate_selector.h" | 12 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" |
| 12 #include "chrome/browser/ssl/ssl_client_certificate_selector_test.h" | 13 #include "chrome/browser/ssl/ssl_client_certificate_selector_test.h" |
| 13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 17 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 18 #include "content/public/browser/client_certificate_delegate.h" |
| 17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
| 19 #include "ui/base/cocoa/window_size_constants.h" | 21 #include "ui/base/cocoa/window_size_constants.h" |
| 20 | 22 |
| 21 using web_modal::WebContentsModalDialogManager; | 23 using web_modal::WebContentsModalDialogManager; |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 void OnCertificateSelected(net::X509Certificate** out_cert, | 27 class TestClientCertificateDelegate |
| 26 int* out_count, | 28 : public content::ClientCertificateDelegate { |
| 27 net::X509Certificate* cert) { | 29 public: |
| 28 *out_cert = cert; | 30 TestClientCertificateDelegate(net::X509Certificate** out_cert, int* out_count) |
| 29 ++(*out_count); | 31 : out_cert_(out_cert), out_count_(out_count) {} |
| 30 } | 32 |
| 33 // content::ClientCertificateDelegate. |
| 34 void ContinueWithCertificate(net::X509Certificate* cert) override { |
| 35 // TODO(davidben): Add a test which explicitly tests selecting a |
| 36 // certificate, or selecting no certificate, since closing the dialog |
| 37 // (normally by closing the tab) is not the same as explicitly selecting no |
| 38 // certificate. |
| 39 ADD_FAILURE() << "Certificate selected"; |
| 40 } |
| 41 |
| 42 void CancelCertificateSelection() override { |
| 43 if (out_cert_) |
| 44 *out_cert_ = nullptr; |
| 45 if (out_count_) |
| 46 ++(*out_count_); |
| 47 } |
| 48 |
| 49 private: |
| 50 net::X509Certificate** out_cert_; |
| 51 int* out_count_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(TestClientCertificateDelegate); |
| 54 }; |
| 31 | 55 |
| 32 } // namespace | 56 } // namespace |
| 33 | 57 |
| 34 typedef SSLClientCertificateSelectorTestBase | 58 typedef SSLClientCertificateSelectorTestBase |
| 35 SSLClientCertificateSelectorCocoaTest; | 59 SSLClientCertificateSelectorCocoaTest; |
| 36 | 60 |
| 37 // Flaky on 10.7; crbug.com/313243 | 61 // Flaky on 10.7; crbug.com/313243 |
| 38 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, DISABLED_Basic) { | 62 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, DISABLED_Basic) { |
| 39 // TODO(kbr): re-enable: http://crbug.com/222296 | 63 // TODO(kbr): re-enable: http://crbug.com/222296 |
| 40 if (base::mac::IsOSMountainLionOrLater()) | 64 if (base::mac::IsOSMountainLionOrLater()) |
| 41 return; | 65 return; |
| 42 | 66 |
| 43 content::WebContents* web_contents = | 67 content::WebContents* web_contents = |
| 44 browser()->tab_strip_model()->GetActiveWebContents(); | 68 browser()->tab_strip_model()->GetActiveWebContents(); |
| 45 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 69 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 46 WebContentsModalDialogManager::FromWebContents(web_contents); | 70 WebContentsModalDialogManager::FromWebContents(web_contents); |
| 47 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); | 71 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); |
| 48 | 72 |
| 49 net::X509Certificate* cert = NULL; | 73 net::X509Certificate* cert = NULL; |
| 50 int count = 0; | 74 int count = 0; |
| 51 SSLClientCertificateSelectorCocoa* selector = | 75 SSLClientCertificateSelectorCocoa* selector = |
| 52 [[SSLClientCertificateSelectorCocoa alloc] | 76 [[SSLClientCertificateSelectorCocoa alloc] |
| 53 initWithBrowserContext:web_contents->GetBrowserContext() | 77 initWithBrowserContext:web_contents->GetBrowserContext() |
| 54 certRequestInfo:auth_requestor_->cert_request_info_.get() | 78 certRequestInfo:auth_requestor_->cert_request_info_.get() |
| 55 callback:base::Bind(&OnCertificateSelected, | 79 delegate:scoped_ptr<content::ClientCertificateDelegate>( |
| 56 &cert, | 80 new TestClientCertificateDelegate( |
| 57 &count)]; | 81 &cert, &count))]; |
| 58 [selector displayForWebContents:web_contents]; | 82 [selector displayForWebContents:web_contents]; |
| 59 content::RunAllPendingInMessageLoop(); | 83 content::RunAllPendingInMessageLoop(); |
| 60 EXPECT_TRUE([selector panel]); | 84 EXPECT_TRUE([selector panel]); |
| 61 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); | 85 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); |
| 62 | 86 |
| 63 WebContentsModalDialogManager::TestApi test_api( | 87 WebContentsModalDialogManager::TestApi test_api( |
| 64 web_contents_modal_dialog_manager); | 88 web_contents_modal_dialog_manager); |
| 65 test_api.CloseAllDialogs(); | 89 test_api.CloseAllDialogs(); |
| 66 content::RunAllPendingInMessageLoop(); | 90 content::RunAllPendingInMessageLoop(); |
| 67 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); | 91 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); |
| 68 | 92 |
| 69 EXPECT_EQ(NULL, cert); | 93 EXPECT_EQ(NULL, cert); |
| 70 EXPECT_EQ(1, count); | 94 EXPECT_EQ(1, count); |
| 71 } | 95 } |
| 72 | 96 |
| 73 // Test that switching to another tab correctly hides the sheet. | 97 // Test that switching to another tab correctly hides the sheet. |
| 74 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, HideShow) { | 98 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, HideShow) { |
| 75 content::WebContents* web_contents = | 99 content::WebContents* web_contents = |
| 76 browser()->tab_strip_model()->GetActiveWebContents(); | 100 browser()->tab_strip_model()->GetActiveWebContents(); |
| 77 SSLClientCertificateSelectorCocoa* selector = | 101 SSLClientCertificateSelectorCocoa* selector = |
| 78 [[SSLClientCertificateSelectorCocoa alloc] | 102 [[SSLClientCertificateSelectorCocoa alloc] |
| 79 initWithBrowserContext:web_contents->GetBrowserContext() | 103 initWithBrowserContext:web_contents->GetBrowserContext() |
| 80 certRequestInfo:auth_requestor_->cert_request_info_.get() | 104 certRequestInfo:auth_requestor_->cert_request_info_.get() |
| 81 callback:chrome::SelectCertificateCallback()]; | 105 delegate:scoped_ptr<content::ClientCertificateDelegate>( |
| 106 new TestClientCertificateDelegate( |
| 107 nullptr, nullptr))]; |
| 82 [selector displayForWebContents:web_contents]; | 108 [selector displayForWebContents:web_contents]; |
| 83 content::RunAllPendingInMessageLoop(); | 109 content::RunAllPendingInMessageLoop(); |
| 84 | 110 |
| 85 NSWindow* sheetWindow = [[selector overlayWindow] attachedSheet]; | 111 NSWindow* sheetWindow = [[selector overlayWindow] attachedSheet]; |
| 86 NSRect sheetFrame = [sheetWindow frame]; | 112 NSRect sheetFrame = [sheetWindow frame]; |
| 87 EXPECT_EQ(1.0, [sheetWindow alphaValue]); | 113 EXPECT_EQ(1.0, [sheetWindow alphaValue]); |
| 88 | 114 |
| 89 // Switch to another tab and verify that the sheet is hidden. | 115 // Switch to another tab and verify that the sheet is hidden. |
| 90 AddBlankTabAndShow(browser()); | 116 AddBlankTabAndShow(browser()); |
| 91 EXPECT_EQ(0.0, [sheetWindow alphaValue]); | 117 EXPECT_EQ(0.0, [sheetWindow alphaValue]); |
| 92 EXPECT_TRUE(NSEqualRects(ui::kWindowSizeDeterminedLater, | 118 EXPECT_TRUE(NSEqualRects(ui::kWindowSizeDeterminedLater, |
| 93 [sheetWindow frame])); | 119 [sheetWindow frame])); |
| 94 | 120 |
| 95 // Switch back and verify that the sheet is shown. | 121 // Switch back and verify that the sheet is shown. |
| 96 chrome::SelectNumberedTab(browser(), 0); | 122 chrome::SelectNumberedTab(browser(), 0); |
| 97 EXPECT_EQ(1.0, [sheetWindow alphaValue]); | 123 EXPECT_EQ(1.0, [sheetWindow alphaValue]); |
| 98 EXPECT_TRUE(NSEqualRects(sheetFrame, [sheetWindow frame])); | 124 EXPECT_TRUE(NSEqualRects(sheetFrame, [sheetWindow frame])); |
| 99 } | 125 } |
| OLD | NEW |