OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/certificate_viewer.h" | 5 #import "chrome/browser/certificate_viewer.h" |
6 | 6 |
7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/browser_commands.h" | 8 #include "chrome/browser/ui/browser_commands.h" |
9 #include "chrome/browser/ui/cocoa/certificate_viewer_mac_cocoa.h" | 9 #include "chrome/browser/ui/cocoa/certificate_viewer_mac.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
12 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 12 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "content/public/test/test_utils.h" | 14 #include "content/public/test/test_utils.h" |
15 #include "net/base/test_data_directory.h" | 15 #include "net/base/test_data_directory.h" |
16 #include "net/cert/x509_certificate.h" | 16 #include "net/cert/x509_certificate.h" |
17 #include "net/test/cert_test_util.h" | 17 #include "net/test/cert_test_util.h" |
18 #import "testing/gtest_mac.h" | 18 #import "testing/gtest_mac.h" |
19 #include "ui/base/cocoa/window_size_constants.h" | 19 #include "ui/base/cocoa/window_size_constants.h" |
20 | 20 |
21 using web_modal::WebContentsModalDialogManager; | 21 using web_modal::WebContentsModalDialogManager; |
22 | 22 |
23 typedef InProcessBrowserTest SSLCertificateViewerCocoaTest; | 23 typedef InProcessBrowserTest SSLCertificateViewerMacTest; |
24 | 24 |
25 namespace { | 25 namespace { |
26 scoped_refptr<net::X509Certificate> GetSampleCertificate() { | 26 scoped_refptr<net::X509Certificate> GetSampleCertificate() { |
27 return net::ImportCertFromFile(net::GetTestCertsDirectory(), | 27 return net::ImportCertFromFile(net::GetTestCertsDirectory(), |
28 "mit.davidben.der"); | 28 "mit.davidben.der"); |
29 } | 29 } |
30 | |
31 void CheckCertificateViewerVisibility(gfx::NativeWindow overlay_window, | |
tapted
2016/06/07 05:33:43
nit: these can just use NSWindow instead of gfx::N
Patti Lor
2016/06/08 00:14:37
Done.
| |
32 gfx::NativeWindow dialog_sheet, | |
33 bool visible) { | |
34 CGFloat alpha = visible ? 1.0 : 0.0; | |
35 BOOL ignore_events = visible ? NO : YES; | |
36 | |
37 // Check the overlay window underneath the certificate viewer is blocking | |
38 // mouse events. | |
39 EXPECT_EQ(ignore_events, [overlay_window ignoresMouseEvents]); | |
tapted
2016/06/07 05:33:42
One thing to be aware of: the output of the tests
Patti Lor
2016/06/08 00:14:37
Done.
| |
40 // Check the certificate viewer sheet is visible and accepting mouse events. | |
41 ASSERT_TRUE(dialog_sheet); | |
tapted
2016/06/07 05:33:43
EXPECT_TRUE
(ASSERT has odd semantics -- it's bas
Patti Lor
2016/06/08 00:14:38
Done.
| |
42 EXPECT_EQ(alpha, [dialog_sheet alphaValue]); | |
43 EXPECT_EQ(ignore_events, [dialog_sheet ignoresMouseEvents]); | |
44 } | |
30 } // namespace | 45 } // namespace |
tapted
2016/06/07 05:33:43
nit: blank line before (there should be one at the
Patti Lor
2016/06/08 00:14:37
Done.
| |
31 | 46 |
32 IN_PROC_BROWSER_TEST_F(SSLCertificateViewerCocoaTest, Basic) { | 47 IN_PROC_BROWSER_TEST_F(SSLCertificateViewerMacTest, Basic) { |
33 scoped_refptr<net::X509Certificate> cert = GetSampleCertificate(); | 48 scoped_refptr<net::X509Certificate> cert = GetSampleCertificate(); |
34 ASSERT_TRUE(cert.get()); | 49 ASSERT_TRUE(cert.get()); |
35 content::WebContents* web_contents = | 50 content::WebContents* web_contents = |
36 browser()->tab_strip_model()->GetActiveWebContents(); | 51 browser()->tab_strip_model()->GetActiveWebContents(); |
37 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow(); | 52 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow(); |
38 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 53 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
39 WebContentsModalDialogManager::FromWebContents(web_contents); | 54 WebContentsModalDialogManager::FromWebContents(web_contents); |
40 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); | 55 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); |
41 | 56 |
42 ShowCertificateViewer(web_contents, window, cert.get()); | 57 ShowCertificateViewer(web_contents, window, cert.get()); |
43 | 58 |
44 content::RunAllPendingInMessageLoop(); | 59 content::RunAllPendingInMessageLoop(); |
45 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); | 60 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); |
46 | 61 |
47 WebContentsModalDialogManager::TestApi test_api( | 62 WebContentsModalDialogManager::TestApi test_api( |
48 web_contents_modal_dialog_manager); | 63 web_contents_modal_dialog_manager); |
49 test_api.CloseAllDialogs(); | 64 test_api.CloseAllDialogs(); |
50 content::RunAllPendingInMessageLoop(); | 65 content::RunAllPendingInMessageLoop(); |
51 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); | 66 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); |
52 } | 67 } |
53 | 68 |
54 // Test that switching to another tab correctly hides the sheet. | 69 // Test that switching to another tab correctly hides the sheet. |
55 IN_PROC_BROWSER_TEST_F(SSLCertificateViewerCocoaTest, HideShow) { | 70 IN_PROC_BROWSER_TEST_F(SSLCertificateViewerMacTest, HideShow) { |
56 scoped_refptr<net::X509Certificate> cert = GetSampleCertificate(); | 71 scoped_refptr<net::X509Certificate> cert = GetSampleCertificate(); |
57 ASSERT_TRUE(cert.get()); | 72 ASSERT_TRUE(cert.get()); |
58 content::WebContents* web_contents = | 73 content::WebContents* web_contents = |
59 browser()->tab_strip_model()->GetActiveWebContents(); | 74 browser()->tab_strip_model()->GetActiveWebContents(); |
60 | 75 |
61 // TODO(patricialor): Display the certificate viewer in a cross-toolkit manner | 76 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow(); |
62 // and retrieve |sheetWindow| via the WebContentsModalDialogManager::TestApi. | 77 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
63 // See https://crbug.com/613880. | 78 WebContentsModalDialogManager::FromWebContents(web_contents); |
64 SSLCertificateViewerCocoa* viewer = | |
65 [[SSLCertificateViewerCocoa alloc] initWithCertificate:cert.get()]; | |
66 [viewer displayForWebContents:web_contents]; | |
67 | 79 |
80 // Account for any child windows that might be present before the certificate | |
81 // viewer is open. | |
82 NSUInteger num_child_windows = [[window childWindows] count]; | |
83 ShowCertificateViewer(web_contents, window, cert.get()); | |
68 content::RunAllPendingInMessageLoop(); | 84 content::RunAllPendingInMessageLoop(); |
85 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); | |
69 | 86 |
70 // TODO(patricialor): Remove the overlayWindow accessor from | 87 ASSERT_TRUE((num_child_windows + 1) == [[window childWindows] count]); |
tapted
2016/06/07 05:33:42
EXPECT_EQ(num_child_windows + 1, [[window childWin
Patti Lor
2016/06/08 00:14:37
Done.
| |
71 // SSLCertificateViewerMac when the overlay is obtained via | 88 gfx::NativeWindow overlay_window = [[window childWindows] lastObject]; |
tapted
2016/06/07 05:33:43
comment before:
// Assume the last child is the o
Patti Lor
2016/06/08 00:14:37
Done.
| |
72 // WebContentsModalDialogManager::TestApi instead - https://crbug.com/613880. | 89 gfx::NativeWindow dialog_sheet = [overlay_window attachedSheet]; |
tapted
2016/06/07 05:33:42
EXPECT_TRUE(dialog_sheet) after this
Patti Lor
2016/06/08 00:14:37
Done.
| |
73 NSWindow* sheetWindow = [[viewer overlayWindow] attachedSheet]; | 90 NSRect sheetFrame = [dialog_sheet frame]; |
tapted
2016/06/07 05:33:43
sheetFrame -> sheet_frame
Patti Lor
2016/06/08 00:14:37
Done.
| |
74 NSRect sheetFrame = [sheetWindow frame]; | |
75 EXPECT_EQ(1.0, [sheetWindow alphaValue]); | |
76 | 91 |
77 // Switch to another tab and verify that the sheet is hidden. | 92 // Verify the certificate viewer is showing and accepts mouse events. |
93 CheckCertificateViewerVisibility(overlay_window, dialog_sheet, true); | |
94 | |
95 // Switch to another tab and verify that |overlay_window| and |dialog_sheet| | |
96 // are not blocking mouse events, and |dialog_sheet| is hidden. | |
78 AddBlankTabAndShow(browser()); | 97 AddBlankTabAndShow(browser()); |
79 EXPECT_EQ(0.0, [sheetWindow alphaValue]); | 98 CheckCertificateViewerVisibility(overlay_window, dialog_sheet, false); |
80 EXPECT_NSEQ(sheetFrame, [sheetWindow frame]); | 99 EXPECT_NSEQ(sheetFrame, [dialog_sheet frame]); |
81 | 100 |
82 // Switch back and verify that the sheet is shown. | 101 // Switch back and verify that the sheet is shown. |
83 chrome::SelectNumberedTab(browser(), 0); | 102 chrome::SelectNumberedTab(browser(), 0); |
103 CheckCertificateViewerVisibility(overlay_window, dialog_sheet, true); | |
104 | |
105 WebContentsModalDialogManager::TestApi test_api( | |
106 web_contents_modal_dialog_manager); | |
107 test_api.CloseAllDialogs(); | |
tapted
2016/06/07 05:33:43
was this needed for something? (comment?)
Patti Lor
2016/06/08 00:14:38
Nope, removed.
| |
84 content::RunAllPendingInMessageLoop(); | 108 content::RunAllPendingInMessageLoop(); |
85 EXPECT_EQ(1.0, [sheetWindow alphaValue]); | |
86 EXPECT_NSEQ(sheetFrame, [sheetWindow frame]); | |
87 } | 109 } |
OLD | NEW |