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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa.h"
7 #import <SecurityInterface/SFChooseIdentityPanel.h>
10 #import "base/mac/mac_util.h"
11 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
12 #include "chrome/browser/ssl/ssl_client_certificate_selector_test.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "components/web_modal/web_contents_modal_dialog_manager.h"
17 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_contents_view.h"
19 #include "content/public/test/test_utils.h"
20 #include "ui/base/cocoa/window_size_constants.h"
22 using web_modal::WebContentsModalDialogManager;
26 void OnCertificateSelected(net::X509Certificate** out_cert,
28 net::X509Certificate* cert) {
35 typedef SSLClientCertificateSelectorTestBase
36 SSLClientCertificateSelectorCocoaTest;
38 // Flaky on 10.7; crbug.com/313243
39 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, DISABLED_Basic) {
40 // TODO(kbr): re-enable: http://crbug.com/222296
41 if (base::mac::IsOSMountainLionOrLater())
44 content::WebContents* web_contents =
45 browser()->tab_strip_model()->GetActiveWebContents();
46 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
47 WebContentsModalDialogManager::FromWebContents(web_contents);
48 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive());
50 net::X509Certificate* cert = NULL;
52 SSLClientCertificateSelectorCocoa* selector =
53 [[SSLClientCertificateSelectorCocoa alloc]
54 initWithNetworkSession:auth_requestor_->http_network_session_
55 certRequestInfo:auth_requestor_->cert_request_info_
56 callback:base::Bind(&OnCertificateSelected,
59 [selector displayForWebContents:web_contents];
60 content::RunAllPendingInMessageLoop();
61 EXPECT_TRUE([selector panel]);
62 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive());
64 WebContentsModalDialogManager::TestApi test_api(
65 web_contents_modal_dialog_manager);
66 test_api.CloseAllDialogs();
67 content::RunAllPendingInMessageLoop();
68 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive());
70 EXPECT_EQ(NULL, cert);
74 // Test that switching to another tab correctly hides the sheet.
75 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, HideShow) {
76 SSLClientCertificateSelectorCocoa* selector =
77 [[SSLClientCertificateSelectorCocoa alloc]
78 initWithNetworkSession:auth_requestor_->http_network_session_
79 certRequestInfo:auth_requestor_->cert_request_info_
80 callback:chrome::SelectCertificateCallback()];
81 content::WebContents* web_contents =
82 browser()->tab_strip_model()->GetActiveWebContents();
83 [selector displayForWebContents:web_contents];
84 content::RunAllPendingInMessageLoop();
86 NSWindow* sheetWindow = [[selector overlayWindow] attachedSheet];
87 NSRect sheetFrame = [sheetWindow frame];
88 EXPECT_EQ(1.0, [sheetWindow alphaValue]);
90 // Switch to another tab and verify that the sheet is hidden.
91 AddBlankTabAndShow(browser());
92 EXPECT_EQ(0.0, [sheetWindow alphaValue]);
93 EXPECT_TRUE(NSEqualRects(ui::kWindowSizeDeterminedLater,
94 [sheetWindow frame]));
96 // Switch back and verify that the sheet is shown.
97 chrome::SelectNumberedTab(browser(), 0);
98 EXPECT_EQ(1.0, [sheetWindow alphaValue]);
99 EXPECT_TRUE(NSEqualRects(sheetFrame, [sheetWindow frame]));