Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: chrome/browser/ui/cocoa/ssl_client_certificate_selector_cocoa_browsertest.mm

Issue 859213006: Cancel client auth requests when not promptable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@client-auth-cancel-1
Patch Set: adjust comment Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Creates a ClientCertificateDelegate that sets |*destroyed| to true on
29 ++(*out_count); 31 // destruction.
30 } 32 explicit TestClientCertificateDelegate(bool* destroyed)
33 : destroyed_(destroyed) { }
34 ~TestClientCertificateDelegate() {
Ryan Sleevi 2015/02/25 06:31:36 override?
Ryan Sleevi 2015/02/25 06:31:36 newline
davidben 2015/02/26 18:09:41 Done.
davidben 2015/02/26 18:09:41 Done.
35 if (destroyed_ != nullptr)
36 *destroyed_ = true;
37 }
38
39 // content::ClientCertificateDelegate.
40 void ContinueWithCertificate(net::X509Certificate* cert) override {
41 // TODO(davidben): Add a test which explicitly tests selecting a
42 // certificate, or selecting no certificate, since closing the dialog
43 // (normally by closing the tab) is not the same as explicitly selecting no
44 // certificate.
45 ADD_FAILURE() << "Certificate selected";
46 }
47
48 private:
49 bool* destroyed_;
50
51 DISALLOW_COPY_AND_ASSIGN(TestClientCertificateDelegate);
52 };
31 53
32 } // namespace 54 } // namespace
33 55
34 typedef SSLClientCertificateSelectorTestBase 56 typedef SSLClientCertificateSelectorTestBase
35 SSLClientCertificateSelectorCocoaTest; 57 SSLClientCertificateSelectorCocoaTest;
36 58
37 // Flaky on 10.7; crbug.com/313243 59 // Flaky on 10.7; crbug.com/313243
38 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, DISABLED_Basic) { 60 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, DISABLED_Basic) {
39 // TODO(kbr): re-enable: http://crbug.com/222296 61 // TODO(kbr): re-enable: http://crbug.com/222296
40 if (base::mac::IsOSMountainLionOrLater()) 62 if (base::mac::IsOSMountainLionOrLater())
41 return; 63 return;
42 64
43 content::WebContents* web_contents = 65 content::WebContents* web_contents =
44 browser()->tab_strip_model()->GetActiveWebContents(); 66 browser()->tab_strip_model()->GetActiveWebContents();
45 WebContentsModalDialogManager* web_contents_modal_dialog_manager = 67 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
46 WebContentsModalDialogManager::FromWebContents(web_contents); 68 WebContentsModalDialogManager::FromWebContents(web_contents);
47 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); 69 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive());
48 70
49 net::X509Certificate* cert = NULL; 71 bool destroyed = false;
50 int count = 0; 72 SSLClientCertificateSelectorCocoa* selector = [
51 SSLClientCertificateSelectorCocoa* selector = 73 [SSLClientCertificateSelectorCocoa alloc]
52 [[SSLClientCertificateSelectorCocoa alloc] 74 initWithBrowserContext:web_contents->GetBrowserContext()
53 initWithBrowserContext:web_contents->GetBrowserContext() 75 certRequestInfo:auth_requestor_->cert_request_info_.get()
54 certRequestInfo:auth_requestor_->cert_request_info_.get() 76 delegate:make_scoped_ptr(new TestClientCertificateDelegate(
55 callback:base::Bind(&OnCertificateSelected, 77 &destroyed))];
56 &cert,
57 &count)];
58 [selector displayForWebContents:web_contents]; 78 [selector displayForWebContents:web_contents];
59 content::RunAllPendingInMessageLoop(); 79 content::RunAllPendingInMessageLoop();
60 EXPECT_TRUE([selector panel]); 80 EXPECT_TRUE([selector panel]);
61 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); 81 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive());
62 82
63 WebContentsModalDialogManager::TestApi test_api( 83 WebContentsModalDialogManager::TestApi test_api(
64 web_contents_modal_dialog_manager); 84 web_contents_modal_dialog_manager);
65 test_api.CloseAllDialogs(); 85 test_api.CloseAllDialogs();
66 content::RunAllPendingInMessageLoop(); 86 content::RunAllPendingInMessageLoop();
67 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); 87 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive());
68 88
69 EXPECT_EQ(NULL, cert); 89 EXPECT_TRUE(destroyed);
70 EXPECT_EQ(1, count);
71 } 90 }
72 91
73 // Test that switching to another tab correctly hides the sheet. 92 // Test that switching to another tab correctly hides the sheet.
74 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, HideShow) { 93 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, HideShow) {
75 content::WebContents* web_contents = 94 content::WebContents* web_contents =
76 browser()->tab_strip_model()->GetActiveWebContents(); 95 browser()->tab_strip_model()->GetActiveWebContents();
77 SSLClientCertificateSelectorCocoa* selector = 96 SSLClientCertificateSelectorCocoa* selector = [
78 [[SSLClientCertificateSelectorCocoa alloc] 97 [SSLClientCertificateSelectorCocoa alloc]
79 initWithBrowserContext:web_contents->GetBrowserContext() 98 initWithBrowserContext:web_contents->GetBrowserContext()
80 certRequestInfo:auth_requestor_->cert_request_info_.get() 99 certRequestInfo:auth_requestor_->cert_request_info_.get()
81 callback:chrome::SelectCertificateCallback()]; 100 delegate:make_scoped_ptr(new TestClientCertificateDelegate(
101 nullptr))];
82 [selector displayForWebContents:web_contents]; 102 [selector displayForWebContents:web_contents];
83 content::RunAllPendingInMessageLoop(); 103 content::RunAllPendingInMessageLoop();
84 104
85 NSWindow* sheetWindow = [[selector overlayWindow] attachedSheet]; 105 NSWindow* sheetWindow = [[selector overlayWindow] attachedSheet];
86 NSRect sheetFrame = [sheetWindow frame]; 106 NSRect sheetFrame = [sheetWindow frame];
87 EXPECT_EQ(1.0, [sheetWindow alphaValue]); 107 EXPECT_EQ(1.0, [sheetWindow alphaValue]);
88 108
89 // Switch to another tab and verify that the sheet is hidden. 109 // Switch to another tab and verify that the sheet is hidden.
90 AddBlankTabAndShow(browser()); 110 AddBlankTabAndShow(browser());
91 EXPECT_EQ(0.0, [sheetWindow alphaValue]); 111 EXPECT_EQ(0.0, [sheetWindow alphaValue]);
92 EXPECT_TRUE(NSEqualRects(ui::kWindowSizeDeterminedLater, 112 EXPECT_TRUE(NSEqualRects(ui::kWindowSizeDeterminedLater,
93 [sheetWindow frame])); 113 [sheetWindow frame]));
94 114
95 // Switch back and verify that the sheet is shown. 115 // Switch back and verify that the sheet is shown.
96 chrome::SelectNumberedTab(browser(), 0); 116 chrome::SelectNumberedTab(browser(), 0);
97 EXPECT_EQ(1.0, [sheetWindow alphaValue]); 117 EXPECT_EQ(1.0, [sheetWindow alphaValue]);
98 EXPECT_TRUE(NSEqualRects(sheetFrame, [sheetWindow frame])); 118 EXPECT_TRUE(NSEqualRects(sheetFrame, [sheetWindow frame]));
99 } 119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698