| 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 "chrome/browser/ssl/ssl_client_certificate_selector.h" | 13 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" |
| 13 #include "chrome/browser/ssl/ssl_client_certificate_selector_test.h" | 14 #include "chrome/browser/ssl/ssl_client_certificate_selector_test.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 18 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 18 #include "content/public/browser/client_certificate_delegate.h" | 19 #include "content/public/browser/client_certificate_delegate.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
| 21 #import "testing/gtest_mac.h" | 22 #import "testing/gtest_mac.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 browser()->tab_strip_model()->GetActiveWebContents(); | 69 browser()->tab_strip_model()->GetActiveWebContents(); |
| 69 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 70 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 70 WebContentsModalDialogManager::FromWebContents(web_contents); | 71 WebContentsModalDialogManager::FromWebContents(web_contents); |
| 71 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); | 72 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); |
| 72 | 73 |
| 73 bool destroyed = false; | 74 bool destroyed = false; |
| 74 SSLClientCertificateSelectorCocoa* selector = [ | 75 SSLClientCertificateSelectorCocoa* selector = [ |
| 75 [SSLClientCertificateSelectorCocoa alloc] | 76 [SSLClientCertificateSelectorCocoa alloc] |
| 76 initWithBrowserContext:web_contents->GetBrowserContext() | 77 initWithBrowserContext:web_contents->GetBrowserContext() |
| 77 certRequestInfo:auth_requestor_->cert_request_info_.get() | 78 certRequestInfo:auth_requestor_->cert_request_info_.get() |
| 78 delegate:make_scoped_ptr(new TestClientCertificateDelegate( | 79 delegate:base::WrapUnique(new TestClientCertificateDelegate( |
| 79 &destroyed))]; | 80 &destroyed))]; |
| 80 [selector displayForWebContents:web_contents]; | 81 [selector displayForWebContents:web_contents]; |
| 81 content::RunAllPendingInMessageLoop(); | 82 content::RunAllPendingInMessageLoop(); |
| 82 EXPECT_TRUE([selector panel]); | 83 EXPECT_TRUE([selector panel]); |
| 83 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); | 84 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); |
| 84 | 85 |
| 85 WebContentsModalDialogManager::TestApi test_api( | 86 WebContentsModalDialogManager::TestApi test_api( |
| 86 web_contents_modal_dialog_manager); | 87 web_contents_modal_dialog_manager); |
| 87 test_api.CloseAllDialogs(); | 88 test_api.CloseAllDialogs(); |
| 88 content::RunAllPendingInMessageLoop(); | 89 content::RunAllPendingInMessageLoop(); |
| 89 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); | 90 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); |
| 90 | 91 |
| 91 EXPECT_TRUE(destroyed); | 92 EXPECT_TRUE(destroyed); |
| 92 } | 93 } |
| 93 | 94 |
| 94 // Test that switching to another tab correctly hides the sheet. | 95 // Test that switching to another tab correctly hides the sheet. |
| 95 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, HideShow) { | 96 IN_PROC_BROWSER_TEST_F(SSLClientCertificateSelectorCocoaTest, HideShow) { |
| 96 content::WebContents* web_contents = | 97 content::WebContents* web_contents = |
| 97 browser()->tab_strip_model()->GetActiveWebContents(); | 98 browser()->tab_strip_model()->GetActiveWebContents(); |
| 98 SSLClientCertificateSelectorCocoa* selector = [ | 99 SSLClientCertificateSelectorCocoa* selector = [ |
| 99 [SSLClientCertificateSelectorCocoa alloc] | 100 [SSLClientCertificateSelectorCocoa alloc] |
| 100 initWithBrowserContext:web_contents->GetBrowserContext() | 101 initWithBrowserContext:web_contents->GetBrowserContext() |
| 101 certRequestInfo:auth_requestor_->cert_request_info_.get() | 102 certRequestInfo:auth_requestor_->cert_request_info_.get() |
| 102 delegate:make_scoped_ptr( | 103 delegate:base::WrapUnique( |
| 103 new TestClientCertificateDelegate(nullptr))]; | 104 new TestClientCertificateDelegate(nullptr))]; |
| 104 [selector displayForWebContents:web_contents]; | 105 [selector displayForWebContents:web_contents]; |
| 105 content::RunAllPendingInMessageLoop(); | 106 content::RunAllPendingInMessageLoop(); |
| 106 | 107 |
| 107 NSWindow* sheetWindow = [[selector overlayWindow] attachedSheet]; | 108 NSWindow* sheetWindow = [[selector overlayWindow] attachedSheet]; |
| 108 NSRect sheetFrame = [sheetWindow frame]; | 109 NSRect sheetFrame = [sheetWindow frame]; |
| 109 EXPECT_EQ(1.0, [sheetWindow alphaValue]); | 110 EXPECT_EQ(1.0, [sheetWindow alphaValue]); |
| 110 | 111 |
| 111 // Switch to another tab and verify that the sheet is hidden. | 112 // Switch to another tab and verify that the sheet is hidden. |
| 112 AddBlankTabAndShow(browser()); | 113 AddBlankTabAndShow(browser()); |
| 113 EXPECT_EQ(0.0, [sheetWindow alphaValue]); | 114 EXPECT_EQ(0.0, [sheetWindow alphaValue]); |
| 114 EXPECT_NSEQ(ui::kWindowSizeDeterminedLater, [sheetWindow frame]); | 115 EXPECT_NSEQ(ui::kWindowSizeDeterminedLater, [sheetWindow frame]); |
| 115 | 116 |
| 116 // Switch back and verify that the sheet is shown. | 117 // Switch back and verify that the sheet is shown. |
| 117 chrome::SelectNumberedTab(browser(), 0); | 118 chrome::SelectNumberedTab(browser(), 0); |
| 118 EXPECT_EQ(1.0, [sheetWindow alphaValue]); | 119 EXPECT_EQ(1.0, [sheetWindow alphaValue]); |
| 119 EXPECT_NSEQ(sheetFrame, [sheetWindow frame]); | 120 EXPECT_NSEQ(sheetFrame, [sheetWindow frame]); |
| 120 } | 121 } |
| OLD | NEW |